use of org.springframework.core.env.CompositePropertySource in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method testCompositeValue.
@Test
public void testCompositeValue() {
PropertySource<?> map = this.propertySources.get("map");
CompositePropertySource composite = new CompositePropertySource("composite");
composite.addPropertySource(map);
this.propertySources.replace("map", composite);
PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues(this.propertySources);
assertThat(propertyValues.getPropertyValue("foo").getValue()).isEqualTo("bar");
}
use of org.springframework.core.env.CompositePropertySource in project apollo by ctripcorp.
the class PropertySourcesProcessor method initializePropertySources.
private void initializePropertySources() {
if (environment.getPropertySources().contains(PropertySourcesConstants.APOLLO_PROPERTY_SOURCE_NAME)) {
// already initialized
return;
}
CompositePropertySource composite = new CompositePropertySource(PropertySourcesConstants.APOLLO_PROPERTY_SOURCE_NAME);
// sort by order asc
ImmutableSortedSet<Integer> orders = ImmutableSortedSet.copyOf(NAMESPACE_NAMES.keySet());
Iterator<Integer> iterator = orders.iterator();
while (iterator.hasNext()) {
int order = iterator.next();
for (String namespace : NAMESPACE_NAMES.get(order)) {
Config config = ConfigService.getConfig(namespace);
composite.addPropertySource(configPropertySourceFactory.getConfigPropertySource(namespace, config));
}
}
// add after the bootstrap property source or to the first
if (environment.getPropertySources().contains(PropertySourcesConstants.APOLLO_BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
environment.getPropertySources().addAfter(PropertySourcesConstants.APOLLO_BOOTSTRAP_PROPERTY_SOURCE_NAME, composite);
} else {
environment.getPropertySources().addFirst(composite);
}
}
use of org.springframework.core.env.CompositePropertySource in project incubator-dubbo-spring-boot-project by apache.
the class EnvironmentUtilsTest method testExtraProperties.
@Test
public void testExtraProperties() {
System.setProperty("user.name", "mercyblitz");
StandardEnvironment environment = new StandardEnvironment();
Map<String, Object> map = new HashMap<>();
map.put("user.name", "Mercy");
MapPropertySource propertySource = new MapPropertySource("first", map);
CompositePropertySource compositePropertySource = new CompositePropertySource("comp");
compositePropertySource.addFirstPropertySource(propertySource);
MutablePropertySources propertySources = environment.getPropertySources();
propertySources.addFirst(compositePropertySource);
Map<String, Object> properties = EnvironmentUtils.extractProperties(environment);
Assert.assertEquals("Mercy", properties.get("user.name"));
}
use of org.springframework.core.env.CompositePropertySource in project spring-cloud-config by spring-cloud.
the class EnvironmentRepositoryPropertySourceLocator method locate.
@Override
public org.springframework.core.env.PropertySource<?> locate(Environment environment) {
CompositePropertySource composite = new CompositePropertySource("configService");
for (PropertySource source : repository.findOne(name, profiles, label).getPropertySources()) {
@SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) source.getSource();
composite.addPropertySource(new MapPropertySource(source.getName(), map));
}
return composite;
}
use of org.springframework.core.env.CompositePropertySource in project BroadleafCommerce by BroadleafCommerce.
the class SpringBootPropertiesTest method testProfileSourcesRegisteredOverridesCommon.
@Test
public void testProfileSourcesRegisteredOverridesCommon() {
Assert.assertTrue(env.getPropertySources().contains(BroadleafEnvironmentConfiguringApplicationListener.FRAMEWORK_SOURCES_NAME));
Assert.assertTrue(env.getPropertySources().contains(BroadleafEnvironmentConfiguringApplicationListener.PROFILE_AWARE_SOURCES_NAME));
String developmentSourceName = new ClassPathResource("common-test-properties/profile-aware-properties/development.properties").getDescription();
CompositePropertySource profileAwareSource = (CompositePropertySource) env.getPropertySources().get(BroadleafEnvironmentConfiguringApplicationListener.PROFILE_AWARE_SOURCES_NAME);
Assert.assertTrue(profileAwareSource.getPropertySources().contains(PropertySource.named(developmentSourceName)));
}
Aggregations