use of org.springframework.core.env.CompositePropertySource in project cas by apereo.
the class DefaultCasConfigurationPropertiesSourceLocator method loadEmbeddedYamlOverriddenProperties.
private PropertySource<?> loadEmbeddedYamlOverriddenProperties(final ResourceLoader resourceLoader, final Environment environment) {
val profiles = ConfigurationPropertiesLoaderFactory.getApplicationProfiles(environment);
val yamlFiles = profiles.stream().map(profile -> String.format("classpath:/application-%s.yml", profile)).sorted().map(resourceLoader::getResource).collect(Collectors.toList());
yamlFiles.add(resourceLoader.getResource("classpath:/application.yml"));
LOGGER.debug("Loading embedded YAML configuration files [{}]", yamlFiles);
val composite = new CompositePropertySource("embeddedYamlOverriddenCompositeProperties");
yamlFiles.forEach(resource -> {
LOGGER.trace("Loading YAML properties from [{}]", resource);
val source = configurationPropertiesLoaderFactory.getLoader(resource, String.format("embeddedYamlOverriddenProperties-%s", resource.getFilename())).load();
composite.addPropertySource(source);
});
return composite;
}
use of org.springframework.core.env.CompositePropertySource in project java-chassis by ServiceComb.
the class GovernanceProperties method getProperties.
private void getProperties(PropertySource<?> propertySource, Set<String> allKeys) {
if (propertySource instanceof CompositePropertySource) {
// recursively get EnumerablePropertySource
CompositePropertySource compositePropertySource = (CompositePropertySource) propertySource;
compositePropertySource.getPropertySources().forEach(ps -> getProperties(ps, allKeys));
return;
}
if (propertySource instanceof EnumerablePropertySource) {
EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) propertySource;
Collections.addAll(allKeys, enumerablePropertySource.getPropertyNames());
return;
}
LOGGER.debug("None EnumerablePropertySource ignored in {}, propertySourceName = [{}]", this.getClass().getName(), propertySource.getName());
}
use of org.springframework.core.env.CompositePropertySource in project spring-framework by spring-projects.
the class ConfigurationClassParser method addPropertySource.
private void addPropertySource(PropertySource<?> propertySource) {
String name = propertySource.getName();
MutablePropertySources propertySources = ((ConfigurableEnvironment) this.environment).getPropertySources();
if (propertySources.contains(name) && this.propertySourceNames.contains(name)) {
// We've already added a version, we need to extend it
PropertySource<?> existing = propertySources.get(name);
PropertySource<?> newSource = (propertySource instanceof ResourcePropertySource ? ((ResourcePropertySource) propertySource).withResourceName() : propertySource);
if (existing instanceof CompositePropertySource) {
((CompositePropertySource) existing).addFirstPropertySource(newSource);
} else {
if (existing instanceof ResourcePropertySource) {
existing = ((ResourcePropertySource) existing).withResourceName();
}
CompositePropertySource composite = new CompositePropertySource(name);
composite.addPropertySource(newSource);
composite.addPropertySource(existing);
propertySources.replace(name, composite);
}
} else {
if (this.propertySourceNames.isEmpty()) {
propertySources.addLast(propertySource);
} else {
String firstProcessed = this.propertySourceNames.get(this.propertySourceNames.size() - 1);
propertySources.addBefore(firstProcessed, propertySource);
}
}
this.propertySourceNames.add(name);
}
use of org.springframework.core.env.CompositePropertySource in project spring-boot by spring-projects.
the class EnvironmentEndpointTests method testCompositeSource.
@SuppressWarnings("unchecked")
@Test
public void testCompositeSource() throws Exception {
EnvironmentEndpoint report = getEndpointBean();
CompositePropertySource source = new CompositePropertySource("composite");
source.addPropertySource(new MapPropertySource("one", Collections.singletonMap("foo", (Object) "bar")));
source.addPropertySource(new MapPropertySource("two", Collections.singletonMap("foo", (Object) "spam")));
this.context.getEnvironment().getPropertySources().addFirst(source);
Map<String, Object> env = report.invoke();
assertThat(((Map<String, Object>) env.get("composite:one")).get("foo")).isEqualTo("bar");
}
use of org.springframework.core.env.CompositePropertySource in project spring-boot by spring-projects.
the class PropertiesConfigurationFactoryMapTests method testBindFromCompositePropertySource.
@Test
public void testBindFromCompositePropertySource() throws Exception {
this.targetName = "foo";
setupFactory();
MutablePropertySources sources = new MutablePropertySources();
CompositePropertySource composite = new CompositePropertySource("composite");
composite.addPropertySource(new MapPropertySource("map", Collections.singletonMap("foo.map.name", (Object) "blah")));
sources.addFirst(composite);
this.factory.setPropertySources(sources);
this.factory.afterPropertiesSet();
Foo foo = this.factory.getObject();
assertThat(foo.map.get("name")).isEqualTo("blah");
}
Aggregations