List of usage examples for org.springframework.web.context ConfigurableWebApplicationContext setConfigLocations
void setConfigLocations(String... configLocations);
From source file:org.pentaho.platform.web.servlet.JAXRSServlet.java
protected ApplicationContext getAppContext() { ConfigurableWebApplicationContext wac = new XmlWebApplicationContext() { @Override//from w w w.j a v a2s .c o m protected Resource getResourceByPath(String path) { return new FileSystemResource(new File(path)); } }; wac.setServletContext(getServletContext()); wac.setServletConfig(getServletConfig()); wac.setNamespace(getServletName()); String springFile = PentahoSystem.getApplicationContext() .getSolutionPath("system" + File.separator + "pentahoServices.spring.xml"); //$NON-NLS-1$ //$NON-NLS-2$ wac.setConfigLocations(new String[] { springFile }); wac.refresh(); return wac; }
From source file:org.red5.server.war.MainServlet.java
/** * Main entry point for the Red5 Server as a war *///from w ww .ja va 2s. c o m // Notification that the web application is ready to process requests public void contextInitialized(ServletContextEvent sce) { System.setProperty("red5.deployment.type", "war"); if (null != servletContext) { return; } servletContext = sce.getServletContext(); String prefix = servletContext.getRealPath("/"); long time = System.currentTimeMillis(); logger.info("RED5 Server (http://www.osflash.org/red5)"); logger.info("Loading red5 global context from: " + red5Config); logger.info("Path: " + prefix); try { // Detect root of Red5 configuration and set as system property String root; String classpath = System.getProperty("java.class.path"); File fp = new File(prefix + red5Config); fp = fp.getCanonicalFile(); if (!fp.isFile()) { // Given file does not exist, search it on the classpath String[] paths = classpath.split(System.getProperty("path.separator")); for (String element : paths) { fp = new File(element + "/" + red5Config); fp = fp.getCanonicalFile(); if (fp.isFile()) { break; } } } if (!fp.isFile()) { throw new Exception( "could not find configuration file " + red5Config + " on your classpath " + classpath); } root = fp.getAbsolutePath(); root = root.replace('\\', '/'); int idx = root.lastIndexOf('/'); root = root.substring(0, idx); // update classpath System.setProperty("java.class.path", classpath + File.pathSeparatorChar + root + File.pathSeparatorChar + root + "/classes"); logger.debug("New classpath: " + System.getProperty("java.class.path")); // set configuration root System.setProperty("red5.config_root", root); logger.info("Setting configuation root to " + root); // Setup system properties so they can be evaluated Properties props = new Properties(); props.load(new FileInputStream(root + "/red5.properties")); for (Object o : props.keySet()) { String key = (String) o; if (StringUtils.isNotBlank(key)) { System.setProperty(key, props.getProperty(key)); } } // Store root directory of Red5 idx = root.lastIndexOf('/'); root = root.substring(0, idx); if (System.getProperty("file.separator").equals("/")) { // Workaround for linux systems root = "/" + root; } System.setProperty("red5.root", root); logger.info("Setting Red5 root to " + root); Class contextClass = org.springframework.web.context.support.XmlWebApplicationContext.class; ConfigurableWebApplicationContext applicationContext = (ConfigurableWebApplicationContext) BeanUtils .instantiateClass(contextClass); String[] strArray = servletContext.getInitParameter(ContextLoader.CONFIG_LOCATION_PARAM) .split("[,\\s]"); logger.info("Config location files: " + strArray.length); applicationContext.setConfigLocations(strArray); applicationContext.setServletContext(servletContext); applicationContext.refresh(); // set web application context as an attribute of the servlet // context so that it may be located via Springs // WebApplicationContextUtils servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); ConfigurableBeanFactory factory = applicationContext.getBeanFactory(); // register default // add the context to the parent factory.registerSingleton("default.context", applicationContext); } catch (Throwable e) { logger.error("", e); } long startupIn = System.currentTimeMillis() - time; logger.info("Startup done in: " + startupIn + " ms"); }
From source file:org.springframework.web.struts.ContextLoaderPlugIn.java
/** * Instantiate the WebApplicationContext for the ActionServlet, either a default * XmlWebApplicationContext or a custom context class if set. This implementation * expects custom contexts to implement ConfigurableWebApplicationContext. * Can be overridden in subclasses.//w ww .jav a2 s .c om * @throws org.springframework.beans.BeansException if the context couldn't be initialized * @see #setContextClass * @see org.springframework.web.context.support.XmlWebApplicationContext */ protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) throws BeansException { if (logger.isDebugEnabled()) { logger.debug("ContextLoaderPlugIn for Struts ActionServlet '" + getServletName() + "', module '" + getModulePrefix() + "' will try to create custom WebApplicationContext " + "context of class '" + getContextClass().getName() + "', using parent context [" + parent + "]"); } if (!ConfigurableWebApplicationContext.class.isAssignableFrom(getContextClass())) { throw new ApplicationContextException( "Fatal initialization error in ContextLoaderPlugIn for Struts ActionServlet '" + getServletName() + "', module '" + getModulePrefix() + "': custom WebApplicationContext class [" + getContextClass().getName() + "] is not of type ConfigurableWebApplicationContext"); } ConfigurableWebApplicationContext wac = (ConfigurableWebApplicationContext) BeanUtils .instantiateClass(getContextClass()); wac.setParent(parent); wac.setServletContext(getServletContext()); wac.setNamespace(getNamespace()); if (getContextConfigLocation() != null) { wac.setConfigLocations(StringUtils.tokenizeToStringArray(getContextConfigLocation(), ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS)); } wac.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() { public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { beanFactory.addBeanPostProcessor(new ActionServletAwareProcessor(getActionServlet())); } }); wac.refresh(); return wac; }
From source file:org.wise.portal.spring.impl.CustomContextLoaderListener.java
/** * The behaviour of this method is the same as the superclass except for * setting of the config locations./* ww w.j ava2 s . c o m*/ * * @throws ClassNotFoundException * * @see org.springframework.web.context.ContextLoader#createWebApplicationContext(javax.servlet.ServletContext, * org.springframework.context.ApplicationContext) */ @Override protected WebApplicationContext createWebApplicationContext(ServletContext servletContext) throws BeansException { Class<?> contextClass = determineContextClass(servletContext); if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) { throw new ApplicationContextException("Custom context class [" + contextClass.getName() + "] is not of type ConfigurableWebApplicationContext"); } ConfigurableWebApplicationContext webApplicationContext = (ConfigurableWebApplicationContext) BeanUtils .instantiateClass(contextClass); webApplicationContext.setServletContext(servletContext); String configClass = servletContext.getInitParameter(CONFIG_CLASS_PARAM); if (configClass != null) { try { SpringConfiguration springConfig = (SpringConfiguration) BeanUtils .instantiateClass(Class.forName(configClass)); webApplicationContext.setConfigLocations(springConfig.getRootApplicationContextConfigLocations()); } catch (ClassNotFoundException e) { if (LOGGER.isErrorEnabled()) { LOGGER.error(CONFIG_CLASS_PARAM + " <" + configClass + "> not found.", e); } throw new InvalidParameterException("ClassNotFoundException: " + configClass); } } else { throw new InvalidParameterException("No value defined for the required: " + CONFIG_CLASS_PARAM); } webApplicationContext.refresh(); return webApplicationContext; }
From source file:ubic.gemma.web.util.WebContextLoader.java
@Override public ApplicationContext loadContext(String... locations) { if (WebContextLoader.logger.isDebugEnabled()) { WebContextLoader.logger.debug("Loading WebApplicationContext for locations [" + StringUtils.arrayToCommaDelimitedString(locations) + "]."); }//from w w w.ja v a 2s.c o m ConfigurableWebApplicationContext context = new XmlWebApplicationContext(); context.setConfigLocations(locations); context.setServletContext(new MockServletContext("")); context.refresh(); AnnotationConfigUtils.registerAnnotationConfigProcessors((BeanDefinitionRegistry) context.getBeanFactory()); context.registerShutdownHook(); return context; }