Files
timi-spring/src/main/java/com/imyeyu/spring/util/YamlPropertySourceFactory.java
2026-01-04 17:27:36 +08:00

31 lines
909 B
Java

package com.imyeyu.spring.util;
import org.springframework.boot.env.YamlPropertySourceLoader;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertySourceFactory;
import java.io.IOException;
import java.util.List;
/**
* Yaml 属性源加载工厂
*
* @author 夜雨
* @since 2025-10-13 16:29
*/
public class YamlPropertySourceFactory implements PropertySourceFactory {
/**
* 创建 Yaml 属性源工厂
*/
public YamlPropertySourceFactory() {
}
@Override
public @org.springframework.lang.NonNull PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
List<PropertySource<?>> sources = new YamlPropertySourceLoader().load(resource.getResource().getFilename(), resource.getResource());
return sources.get(0);
}
}