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;
}
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));
}
}
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 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();
}
Aggregations