use of org.springframework.core.env.StandardEnvironment in project spring-framework by spring-projects.
the class ConfigurationClassPostProcessorTests method assertSupportForComposedAnnotation.
private void assertSupportForComposedAnnotation(RootBeanDefinition beanDefinition) {
beanFactory.registerBeanDefinition("config", beanDefinition);
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.setEnvironment(new StandardEnvironment());
pp.postProcessBeanFactory(beanFactory);
SimpleComponent simpleComponent = beanFactory.getBean(SimpleComponent.class);
assertNotNull(simpleComponent);
}
use of org.springframework.core.env.StandardEnvironment in project spring-framework by spring-projects.
the class PropertySourcesPlaceholderConfigurerTests method customPlaceholderPrefixAndSuffix.
@Test
public void customPlaceholderPrefixAndSuffix() {
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setPlaceholderPrefix("@<");
ppc.setPlaceholderSuffix(">");
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean", rootBeanDefinition(TestBean.class).addPropertyValue("name", "@<key1>").addPropertyValue("sex", "${key2}").getBeanDefinition());
System.setProperty("key1", "systemKey1Value");
System.setProperty("key2", "systemKey2Value");
ppc.setEnvironment(new StandardEnvironment());
ppc.postProcessBeanFactory(bf);
System.clearProperty("key1");
System.clearProperty("key2");
assertThat(bf.getBean(TestBean.class).getName(), is("systemKey1Value"));
assertThat(bf.getBean(TestBean.class).getSex(), is("${key2}"));
}
use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.
the class SpringApplication method convertToStandardEnvironment.
private ConfigurableEnvironment convertToStandardEnvironment(ConfigurableEnvironment environment) {
StandardEnvironment result = new StandardEnvironment();
removeAllPropertySources(result.getPropertySources());
result.setActiveProfiles(environment.getActiveProfiles());
for (PropertySource<?> propertySource : environment.getPropertySources()) {
if (!SERVLET_ENVIRONMENT_SOURCE_NAMES.contains(propertySource.getName())) {
result.getPropertySources().addLast(propertySource);
}
}
return result;
}
use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.
the class ApplicationPidFileWriterTests method createEnvironment.
private ConfigurableEnvironment createEnvironment(String propName, String propValue) {
MockPropertySource propertySource = mockPropertySource(propName, propValue);
ConfigurableEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addLast(propertySource);
return environment;
}
use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.
the class SpringApplicationTests method customEnvironment.
@Test
public void customEnvironment() throws Exception {
TestSpringApplication application = new TestSpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
ConfigurableEnvironment environment = new StandardEnvironment();
application.setEnvironment(environment);
this.context = application.run();
verify(application.getLoader()).setEnvironment(environment);
}
Aggregations