List of usage examples for org.springframework.web.context.support AbstractRefreshableWebApplicationContext getEnvironment
@Override
public ConfigurableEnvironment getEnvironment()
From source file:it.scoppelletti.programmerpower.web.spring.config.WebApplicationContextInitializer.java
/** * Inizializzazione./*from www .j ava2 s . c o m*/ * * @param applCtx Contesto dell’applicazione. */ public void initialize(AbstractRefreshableWebApplicationContext applCtx) { ConfigurableEnvironment env; PropertySource<?> propSource; MutablePropertySources propSources; env = applCtx.getEnvironment(); // Acquisisco gli eventuali profili configurati prima di aggiungere // quelli di Programmer Power env.getActiveProfiles(); env.addActiveProfile(WebApplicationContextInitializer.PROFILE); env.addActiveProfile(DataUtils.PROFILE); propSources = env.getPropertySources(); propSource = BeanConfigUtils.loadPropertySource(); if (propSource != null) { propSources.addFirst(propSource); } propSources.addLast(new WebPropertySource(WebPropertySource.class.getName(), applCtx)); }
From source file:org.cloudfoundry.identity.uaa.BootstrapTests.java
private ConfigurableApplicationContext getServletContext(String... resources) { String environmentConfigLocations = "required_configuration.yml,${LOGIN_CONFIG_URL},file:${LOGIN_CONFIG_PATH}/login.yml,file:${CLOUD_FOUNDRY_CONFIG_PATH}/login.yml,${UAA_CONFIG_URL},file:${UAA_CONFIG_FILE},file:${UAA_CONFIG_PATH}/uaa.yml,file:${CLOUD_FOUNDRY_CONFIG_PATH}/uaa.yml"; String profiles = null;//from ww w .j a v a2 s .com String[] resourcesToLoad = resources; if (!resources[0].endsWith(".xml")) { profiles = resources[0]; resourcesToLoad = new String[resources.length - 1]; System.arraycopy(resources, 1, resourcesToLoad, 0, resourcesToLoad.length); } final String[] configLocations = resourcesToLoad; AbstractRefreshableWebApplicationContext context = new AbstractRefreshableWebApplicationContext() { @Override protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException { XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory); // Configure the bean definition reader with this context's // resource loading environment. beanDefinitionReader.setEnvironment(this.getEnvironment()); beanDefinitionReader.setResourceLoader(this); beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this)); if (configLocations != null) { for (String configLocation : configLocations) { beanDefinitionReader.loadBeanDefinitions(configLocation); } } } }; MockServletContext servletContext = new MockServletContext() { @Override public RequestDispatcher getNamedDispatcher(String path) { return new MockRequestDispatcher("/"); } public String getVirtualServerName() { return null; } }; context.setServletContext(servletContext); MockServletConfig servletConfig = new MockServletConfig(servletContext); servletConfig.addInitParameter("environmentConfigLocations", environmentConfigLocations); context.setServletConfig(servletConfig); YamlServletProfileInitializer initializer = new YamlServletProfileInitializer(); initializer.initialize(context); if (profiles != null) { context.getEnvironment().setActiveProfiles(StringUtils.commaDelimitedListToStringArray(profiles)); } context.refresh(); return context; }
From source file:org.cloudfoundry.identity.uaa.login.BootstrapTests.java
private ConfigurableApplicationContext getServletContext(String profiles, String loginYmlPath, String uaaYamlPath, String... resources) { String[] resourcesToLoad = resources; if (!resources[0].endsWith(".xml")) { resourcesToLoad = new String[resources.length - 1]; System.arraycopy(resources, 1, resourcesToLoad, 0, resourcesToLoad.length); }/*from w w w .jav a 2 s .co m*/ final String[] configLocations = resourcesToLoad; AbstractRefreshableWebApplicationContext context = new AbstractRefreshableWebApplicationContext() { @Override protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException { XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory); // Configure the bean definition reader with this context's // resource loading environment. beanDefinitionReader.setEnvironment(this.getEnvironment()); beanDefinitionReader.setResourceLoader(this); beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this)); if (configLocations != null) { for (String configLocation : configLocations) { beanDefinitionReader.loadBeanDefinitions(configLocation); } } } }; if (profiles != null) { context.getEnvironment().setActiveProfiles(StringUtils.commaDelimitedListToStringArray(profiles)); } MockServletContext servletContext = new MockServletContext() { @Override public RequestDispatcher getNamedDispatcher(String path) { return new MockRequestDispatcher("/"); } }; context.setServletContext(servletContext); MockServletConfig servletConfig = new MockServletConfig(servletContext); servletConfig.addInitParameter("environmentConfigLocations", loginYmlPath + "," + uaaYamlPath); context.setServletConfig(servletConfig); YamlServletProfileInitializer initializer = new YamlServletProfileInitializer(); initializer.initialize(context); if (profiles != null) { context.getEnvironment().setActiveProfiles(StringUtils.commaDelimitedListToStringArray(profiles)); } context.refresh(); return context; }