Search in sources :

Example 71 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-framework by spring-projects.

the class ProfileXmlBeanDefinitionTests method beanFactoryFor.

private BeanDefinitionRegistry beanFactoryFor(String xmlName, String... activeProfiles) {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
    StandardEnvironment env = new StandardEnvironment();
    env.setActiveProfiles(activeProfiles);
    reader.setEnvironment(env);
    reader.loadBeanDefinitions(new ClassPathResource(xmlName, getClass()));
    return beanFactory;
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 72 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentBeanFactoryPostProcessor method postProcessBeanFactory.

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    StandardEnvironment environment = (StandardEnvironment) beanFactory.getBean(Environment.class);
    if (environment != null) {
        Map<String, Object> systemEnvironment = environment.getSystemEnvironment();
        Map<String, Object> prefixlessSystemEnvironment = new HashMap<>(systemEnvironment.size());
        systemEnvironment.keySet().forEach(key -> {
            String prefixKey = key;
            for (String propertyPrefix : PROPERTY_PREFIXES) {
                if (key.startsWith(propertyPrefix)) {
                    prefixKey = key.substring(propertyPrefix.length());
                    break;
                }
            }
            prefixlessSystemEnvironment.put(prefixKey, systemEnvironment.get(key));
        });
        environment.getPropertySources().replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, new RelaxedPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, prefixlessSystemEnvironment));
    }
}
Also used : HashMap(java.util.HashMap) Environment(org.springframework.core.env.Environment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) RelaxedPropertySource(io.gravitee.common.util.RelaxedPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 73 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 74 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 75 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.

the class SpringApplicationBindContextLoader method loadContext.

@Override
public ApplicationContext loadContext(MergedContextConfiguration config) throws Exception {
    SpringApplication application = new SpringApplication();
    application.setMainApplicationClass(config.getTestClass());
    application.setWebApplicationType(WebApplicationType.NONE);
    application.setSources(new LinkedHashSet<Object>(Arrays.asList(config.getClasses())));
    ConfigurableEnvironment environment = new StandardEnvironment();
    Map<String, Object> properties = new LinkedHashMap<>();
    properties.put("spring.jmx.enabled", "false");
    properties.putAll(TestPropertySourceUtils.convertInlinedPropertiesToMap(config.getPropertySourceProperties()));
    environment.getPropertySources().addAfter(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, new MapPropertySource("integrationTest", properties));
    application.setEnvironment(environment);
    return application.run();
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplication(org.springframework.boot.SpringApplication) MapPropertySource(org.springframework.core.env.MapPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

StandardEnvironment (org.springframework.core.env.StandardEnvironment)146 Test (org.junit.jupiter.api.Test)63 MapPropertySource (org.springframework.core.env.MapPropertySource)52 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)42 Test (org.junit.Test)39 HashMap (java.util.HashMap)37 URI (java.net.URI)23 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 MutablePropertySources (org.springframework.core.env.MutablePropertySources)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