org.springframework.core.env.StandardEnvironment#setActiveProfiles ( )源码实例Demo

下面列出了org.springframework.core.env.StandardEnvironment#setActiveProfiles ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: super-cloudops   文件: ScmContextRefresher.java
/**
 * Don't use ConfigurableEnvironment.merge() in case there are clashes with
 * property source names
 * 
 * @param input
 * @return
 */
private StandardEnvironment copyEnvironment(ConfigurableEnvironment input) {
	StandardEnvironment environment = new StandardEnvironment();
	MutablePropertySources capturedPropertySources = environment.getPropertySources();

	// Only copy the default property source(s) and the profiles over from
	// the main environment (everything else should be pristine, just like
	// it was on startup).
	for (String name : DEFAULT_PROPERTY_SOURCES) {
		if (input.getPropertySources().contains(name)) {
			if (capturedPropertySources.contains(name)) {
				capturedPropertySources.replace(name, input.getPropertySources().get(name));
			} else {
				capturedPropertySources.addLast(input.getPropertySources().get(name));
			}
		}
	}
	environment.setActiveProfiles(input.getActiveProfiles());
	environment.setDefaultProfiles(input.getDefaultProfiles());

	Map<String, Object> map = new HashMap<String, Object>();
	map.put("spring.jmx.enabled", false);
	map.put("spring.main.sources", "");
	capturedPropertySources.addFirst(new MapPropertySource(SCM_REFRESH_PROPERTY_SOURCE, map));
	return environment;
}
 
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;
}
 
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;
}
 
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;
}
 
源代码5 项目: spring-cloud-commons   文件: ContextRefresher.java
private StandardEnvironment copyEnvironment(ConfigurableEnvironment input) {
	StandardEnvironment environment = new StandardEnvironment();
	MutablePropertySources capturedPropertySources = environment.getPropertySources();
	// Only copy the default property source(s) and the profiles over from the main
	// environment (everything else should be pristine, just like it was on startup).
	for (String name : DEFAULT_PROPERTY_SOURCES) {
		if (input.getPropertySources().contains(name)) {
			if (capturedPropertySources.contains(name)) {
				capturedPropertySources.replace(name,
						input.getPropertySources().get(name));
			}
			else {
				capturedPropertySources.addLast(input.getPropertySources().get(name));
			}
		}
	}
	environment.setActiveProfiles(input.getActiveProfiles());
	environment.setDefaultProfiles(input.getDefaultProfiles());
	Map<String, Object> map = new HashMap<String, Object>();
	map.put("spring.jmx.enabled", false);
	map.put("spring.main.sources", "");
	// gh-678 without this apps with this property set to REACTIVE or SERVLET fail
	map.put("spring.main.web-application-type", "NONE");
	capturedPropertySources
			.addFirst(new MapPropertySource(REFRESH_ARGS_PROPERTY_SOURCE, map));
	return environment;
}
 
private static Environment createEnvironmentWithActiveProfiles(
		String[] activeProfiles) {
	StandardEnvironment environment = new StandardEnvironment();
	environment.setActiveProfiles(activeProfiles);
	return environment;
}