List of usage examples for org.springframework.web.context ConfigurableWebApplicationContext getServletContext
@Nullable ServletContext getServletContext();
From source file:de.dennishoersch.web.chat.spring.profiles.Profiles.java
protected boolean isActive(ConfigurableWebApplicationContext applicationContext) { String serverInfo = applicationContext.getServletContext().getServerInfo(); return serverInfo.toLowerCase().contains(name().toLowerCase()); }
From source file:com.wisemapping.webmvc.ApplicationContextInitializer.java
public void initialize(@NotNull ConfigurableWebApplicationContext ctx) { try {// www . j a v a 2 s. c o m final Resource resource = new ServletContextResource(ctx.getServletContext(), "/WEB-INF/app.properties"); final ResourcePropertySource resourcePropertySource = new ResourcePropertySource(resource); ctx.getEnvironment().getPropertySources().addFirst(resourcePropertySource); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:com.goldengekko.meetr.ContextProfileInitializer.java
public void initialize(ConfigurableWebApplicationContext ctx) { ConfigurableEnvironment environment = ctx.getEnvironment(); final String activeProfiles = ctx.getServletContext().getInitParameter("contxt.profile.initializer.active"); final String[] profiles = activeProfiles.split(","); LOG.info("activating profiles {} from {}", profiles, activeProfiles); environment.setActiveProfiles(profiles); }
From source file:org.n52.wfs.WfsDispatcherServlet.java
@Override protected void postProcessWebApplicationContext(ConfigurableWebApplicationContext wac) { super.postProcessWebApplicationContext(wac); ServletContext servletContext = wac.getServletContext(); wac.setConfigLocation(getConfigLocation(servletContext)); }
From source file:edu.jhuapl.openessence.config.AppInitializer.java
/** * Add builtin properties, i.e. properties added to environment that do not come from .properties files. *//* w w w.j a v a 2s . c o m*/ private MapPropertySource getBuiltinPropertySource(ConfigurableWebApplicationContext ctx) { Map<String, Object> builtinProps = new HashMap<String, Object>(); builtinProps.put("contextPath", ctx.getServletContext().getContextPath()); return new MapPropertySource(BUILTIN_PROP_SOURCE, builtinProps); }
From source file:org.cloudfoundry.identity.uaa.config.YamlServletProfileInitializer.java
@Override public void initialize(ConfigurableWebApplicationContext applicationContext) { Resource resource = null;/*from w ww . ja v a 2s . com*/ ServletContext servletContext = applicationContext.getServletContext(); WebApplicationContextUtils.initServletPropertySources( applicationContext.getEnvironment().getPropertySources(), servletContext, applicationContext.getServletConfig()); ServletConfig servletConfig = applicationContext.getServletConfig(); String locations = servletConfig == null ? null : servletConfig.getInitParameter(PROFILE_CONFIG_FILE_LOCATIONS); resource = getResource(servletContext, applicationContext, locations); if (resource == null) { servletContext.log("No YAML environment properties from servlet. Defaulting to servlet context."); locations = servletContext.getInitParameter(PROFILE_CONFIG_FILE_LOCATIONS); resource = getResource(servletContext, applicationContext, locations); } try { servletContext.log("Loading YAML environment properties from location: " + resource); YamlMapFactoryBean factory = new YamlMapFactoryBean(); factory.setResolutionMethod(ResolutionMethod.OVERRIDE_AND_IGNORE); List<Resource> resources = new ArrayList<Resource>(); String defaultLocation = servletConfig == null ? null : servletConfig.getInitParameter(PROFILE_CONFIG_FILE_DEFAULT); if (defaultLocation != null) { Resource defaultResource = new ClassPathResource(defaultLocation); if (defaultResource.exists()) { resources.add(defaultResource); } } resources.add(resource); factory.setResources(resources.toArray(new Resource[resources.size()])); Map<String, Object> map = factory.getObject(); String yamlStr = (new Yaml()).dump(map); map.put(rawYamlKey, yamlStr); NestedMapPropertySource properties = new NestedMapPropertySource("servletConfigYaml", map); applicationContext.getEnvironment().getPropertySources().addLast(properties); applySpringProfiles(applicationContext.getEnvironment(), servletContext); applyLog4jConfiguration(applicationContext.getEnvironment(), servletContext); } catch (Exception e) { servletContext.log("Error loading YAML environment properties from location: " + resource, e); } }
From source file:com.indeed.imhotep.web.config.PropertiesInitializer.java
protected List<String> getTomcatContextPropertyLocations(ConfigurableApplicationContext applicationContext) { if (!(applicationContext instanceof ConfigurableWebApplicationContext)) { return Collections.emptyList(); }/* w w w . j a v a2s .c om*/ ConfigurableWebApplicationContext webApplicationContext = (ConfigurableWebApplicationContext) applicationContext; List<String> locations = Lists.newArrayList(); for (String propertiesParameterName : getContextPropertiesParameterNames()) { final String tomcatContextPropertiesFile = webApplicationContext.getServletContext() .getInitParameter(propertiesParameterName); locations.add("file:" + tomcatContextPropertiesFile); } return locations; }
From source file:com.katsu.dwm.springframework.Loader.java
public void load(File jar, Properties properties) throws MalformedURLException { ConfigurableWebApplicationContext wac = (ConfigurableWebApplicationContext) BeanUtils .instantiateClass(XmlWebApplicationContext.class); //FIXME/* www.j a va 2 s .c om*/ wac.setId("test-context"); wac.setParent(applicationContext); wac.setServletContext(((XmlWebApplicationContext) applicationContext).getServletContext()); //wac.setServletConfig(((XmlWebApplicationContext) applicationContext).getServletConfig()); //wac.setNamespace(((XmlWebApplicationContext) applicationContext).getNamespace()); wac.setConfigLocation(properties.getProperty(LoaderConst.CONTEXT_LOCATION.getValue())); //wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener())); wac.refresh(); wac.getServletContext().setAttribute("test-context", wac); }