Search in sources :

Example 31 with StandardEnvironment

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);
}
Also used : SimpleComponent(org.springframework.context.annotation.componentscan.simple.SimpleComponent) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 32 with StandardEnvironment

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}"));
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 33 with StandardEnvironment

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;
}
Also used : StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 34 with StandardEnvironment

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;
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MockPropertySource(org.springframework.mock.env.MockPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 35 with StandardEnvironment

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);
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Aggregations

StandardEnvironment (org.springframework.core.env.StandardEnvironment)55 Test (org.junit.Test)41 MapPropertySource (org.springframework.core.env.MapPropertySource)28 URI (java.net.URI)23 HashMap (java.util.HashMap)23 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)18 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)15 RestTemplate (org.springframework.web.client.RestTemplate)15 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)14 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)14 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)14 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)14 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)13 QueuingWebSocketListener (com.kixeye.chassis.transport.websocket.QueuingWebSocketListener)9 WebSocketMessageRegistry (com.kixeye.chassis.transport.websocket.WebSocketMessageRegistry)9 Envelope (com.kixeye.chassis.transport.dto.Envelope)7 ArrayList (java.util.ArrayList)7