use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class SpringBootContextLoader method convertToPropertySources.
private PropertySources convertToPropertySources(List<String> properties) {
Map<String, Object> source = TestPropertySourceUtils.convertInlinedPropertiesToMap(properties.toArray(new String[properties.size()]));
MutablePropertySources sources = new MutablePropertySources();
sources.addFirst(new MapPropertySource("inline", source));
return sources;
}
use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class ServerPortInfoApplicationContextInitializer method setPortProperty.
@SuppressWarnings("unchecked")
private void setPortProperty(ConfigurableEnvironment environment, String propertyName, int port) {
MutablePropertySources sources = environment.getPropertySources();
PropertySource<?> source = sources.get("server.ports");
if (source == null) {
source = new MapPropertySource("server.ports", new HashMap<String, Object>());
sources.addFirst(source);
}
((Map<String, Object>) source.getSource()).put(propertyName, port);
}
use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class CloudFoundryVcapEnvironmentPostProcessor method postProcessEnvironment.
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) {
Properties properties = new Properties();
addWithPrefix(properties, getPropertiesFromApplication(environment), "vcap.application.");
addWithPrefix(properties, getPropertiesFromServices(environment), "vcap.services.");
MutablePropertySources propertySources = environment.getPropertySources();
if (propertySources.contains(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) {
propertySources.addAfter(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME, new PropertiesPropertySource("vcap", properties));
} else {
propertySources.addFirst(new PropertiesPropertySource("vcap", properties));
}
}
}
use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class ConfigurationPropertiesBindingPostProcessor method deducePropertySources.
private PropertySources deducePropertySources() {
PropertySourcesPlaceholderConfigurer configurer = getSinglePropertySourcesPlaceholderConfigurer();
if (configurer != null) {
// Flatten the sources into a single list so they can be iterated
return new FlatPropertySources(configurer.getAppliedPropertySources());
}
if (this.environment instanceof ConfigurableEnvironment) {
MutablePropertySources propertySources = ((ConfigurableEnvironment) this.environment).getPropertySources();
return new FlatPropertySources(propertySources);
}
// empty, so not very useful, but fulfils the contract
logger.warn("Unable to obtain PropertySources from " + "PropertySourcesPlaceholderConfigurer or Environment");
return new MutablePropertySources();
}
use of org.springframework.core.env.MutablePropertySources in project spring-boot by spring-projects.
the class PropertiesConfigurationFactoryTests method testBindWithDashPrefix.
@Test
public void testBindWithDashPrefix() throws Exception {
// gh-4045
this.targetName = "foo-bar";
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addLast(new SystemEnvironmentPropertySource("systemEnvironment", Collections.<String, Object>singletonMap("FOO_BAR_NAME", "blah")));
propertySources.addLast(new RandomValuePropertySource());
setupFactory();
this.factory.setPropertySources(propertySources);
this.factory.afterPropertiesSet();
Foo foo = this.factory.getObject();
assertThat(foo.name).isEqualTo("blah");
}
Aggregations