List of usage examples for org.springframework.web.context ContextLoader CONFIG_LOCATION_PARAM
String CONFIG_LOCATION_PARAM
To view the source code for org.springframework.web.context ContextLoader CONFIG_LOCATION_PARAM.
Click Source Link
From source file:org.parancoe.web.test.BaseTest.java
@Override protected ConfigurableApplicationContext createApplicationContext(String[] locations) { FileSystemResourceLoader rl = new FileSystemResourceLoader(); MockServletContext servletContext = new MockServletContext(rl); servletContext.setMinorVersion(4);/*from w w w. j a v a2s. co m*/ servletContext.registerContext("/test", servletContext); servletContext.setServletContextName("/test"); servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, arrayToString(locations)); ContextLoader loader = new ContextLoader(); WebApplicationContext context = loader.initWebApplicationContext(servletContext); return (ConfigurableApplicationContext) context; }
From source file:org.red5.server.war.MainServlet.java
/** * Main entry point for the Red5 Server as a war *///from ww w. jav a 2s. co 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"); }