com.muizz.spring.mediator.configuration.YamlPropertySourceFactory Maven / Gradle / Ivy
package com.muizz.spring.mediator.configuration;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertySourceFactory;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
public class YamlPropertySourceFactory implements PropertySourceFactory {
@Override
public PropertySource> createPropertySource(String name, EncodedResource encodedResource) {
String activeProfile = Optional
.ofNullable(System.getenv("SPRING_PROFILES_ACTIVE"))
.orElse(System.getProperty("spring.profiles.active"));
assert activeProfile != null;
YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
yamlFactory.setResources(encodedResource.getResource());
Properties properties = yamlFactory.getObject();
assert properties != null;
return new PropertiesPropertySource(Objects.requireNonNull(encodedResource.getResource().getFilename()), properties);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy