use of org.springframework.core.env.PropertiesPropertySource 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.PropertiesPropertySource in project spring-boot by spring-projects.
the class PropertiesConfigurationFactoryTests method bindFoo.
private Foo bindFoo(final String values) throws Exception {
Properties properties = PropertiesLoaderUtils.loadProperties(new ByteArrayResource(values.getBytes()));
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new PropertiesPropertySource("test", properties));
this.factory.setPropertySources(propertySources);
this.factory.afterPropertiesSet();
return this.factory.getObject();
}
use of org.springframework.core.env.PropertiesPropertySource in project spring-boot by spring-projects.
the class RelaxedPropertyResolverTests method testPropertySource.
@Test
public void testPropertySource() throws Exception {
Properties properties;
PropertiesPropertySource propertySource;
String propertyPrefix = "spring.datasource.";
String propertyName = "password";
String fullPropertyName = propertyPrefix + propertyName;
StandardEnvironment environment = new StandardEnvironment();
MutablePropertySources sources = environment.getPropertySources();
properties = new Properties();
properties.put(fullPropertyName, "systemPassword");
propertySource = new PropertiesPropertySource("system", properties);
sources.addLast(propertySource);
properties = new Properties();
properties.put(fullPropertyName, "propertiesPassword");
propertySource = new PropertiesPropertySource("properties", properties);
sources.addLast(propertySource);
RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(environment, propertyPrefix);
String directProperty = propertyResolver.getProperty(propertyName);
Map<String, Object> subProperties = propertyResolver.getSubProperties("");
String subProperty = (String) subProperties.get(propertyName);
assertThat(subProperty).isEqualTo(directProperty);
}
use of org.springframework.core.env.PropertiesPropertySource in project spring-boot by spring-projects.
the class PropertiesConfigurationFactoryMapTests method bindFoo.
private Foo bindFoo(final String values) throws Exception {
Properties properties = PropertiesLoaderUtils.loadProperties(new ByteArrayResource(values.getBytes()));
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new PropertiesPropertySource("test", properties));
this.factory.setPropertySources(propertySources);
this.factory.afterPropertiesSet();
return this.factory.getObject();
}
use of org.springframework.core.env.PropertiesPropertySource in project spring-boot by spring-projects.
the class PropertiesConfigurationFactoryParameterizedTests method bindFoo.
private Foo bindFoo(final String values) throws Exception {
Properties properties = PropertiesLoaderUtils.loadProperties(new ByteArrayResource(values.getBytes()));
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new PropertiesPropertySource("test", properties));
this.factory.setPropertySources(propertySources);
this.factory.afterPropertiesSet();
return this.factory.getObject();
}
Aggregations