add YamlPropertySourceFactory

This commit is contained in:
Timi
2025-10-29 11:20:59 +08:00
parent 69d847f337
commit 8de027e0c7

View File

@ -0,0 +1,24 @@
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;
/**
*
*
* @author 夜雨
* @since 2025-10-13 16:29
*/
public class YamlPropertySourceFactory implements PropertySourceFactory {
@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);
}
}