List of usage examples for org.springframework.web.context ContextLoader ContextLoader
public ContextLoader()
From source file:org.springside.modules.test.spring.SpringWebTestHelper.java
/** * ServletContext?Spring WebApplicationContext. * /* w w w . j av a 2s. com*/ * @param configLocations application context. */ public static void initWebApplicationContext(MockServletContext servletContext, String... configLocations) { String configLocationsString = StringUtils.join(configLocations, ","); servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, configLocationsString); new ContextLoader().initWebApplicationContext(servletContext); }
From source file:org.springside.modules.test.spring.SpringWebTestHelper.java
/** * ServletContextSpring WebApplicationContext. *//*from www . j a v a 2s . c o m*/ public static void closeWebApplicationContext(MockServletContext servletContext) { new ContextLoader().closeWebApplicationContext(servletContext); }
From source file:no.dusken.aranea.spring.AraneaContextLoaderListener.java
@Override protected ContextLoader createContextLoader() { return new ContextLoader() { @Override//from w ww . j a va2s . c o m protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext configurableWebApplicationContext) { addDeveloperModeReplacer(configurableWebApplicationContext); } }; }
From source file:dk.frankbille.scoreboard.test.WicketSpringTestCase.java
@BeforeClass public static void setupSpring() { if (applicationContext == null) { MockServletContext servletContext = new MockServletContext(new ScoreBoardApplication(), "src/main/webapp"); servletContext.addInitParameter("contextConfigLocation", "classpath:applicationContext-test.xml"); ContextLoader loader = new ContextLoader(); applicationContext = loader.initWebApplicationContext(servletContext); WicketSpringTestCase.servletContext = servletContext; }//from w w w . j a v a 2s . c o m }
From source file:org.apache.wink.test.mock.SpringAwareTestCase.java
@Override protected void setUp() throws Exception { super.setUp(); ContextLoader contextLoader = new ContextLoader(); servletContext = new MockServletContext(); servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, getApplicationContextPath()); applicationContext = contextLoader.initWebApplicationContext(servletContext); }
From source file:net.jawr.web.bundle.processor.spring.SpringControllerBundleProcessor.java
/** * Initialize the servlets which will handle the request to the JawrSpringController * @param servletContext the servlet context * @return the list of servlet definition for the JawrSpringControllers * @throws ServletException if a servlet exception occurs *///from w w w .ja v a 2s. c o m @SuppressWarnings("rawtypes") public List<ServletDefinition> initJawrSpringServlets(ServletContext servletContext) throws ServletException { List<ServletDefinition> jawrServletDefinitions = new ArrayList<ServletDefinition>(); ContextLoader contextLoader = new ContextLoader(); WebApplicationContext applicationCtx = contextLoader.initWebApplicationContext(servletContext); Map<?, ?> jawrControllersMap = applicationCtx.getBeansOfType(JawrSpringController.class); Iterator<?> entrySetIterator = jawrControllersMap.entrySet().iterator(); while (entrySetIterator.hasNext()) { JawrSpringController jawrController = (JawrSpringController) ((Map.Entry) entrySetIterator.next()) .getValue(); Map<String, Object> initParams = new HashMap<String, Object>(); initParams.putAll(jawrController.getInitParams()); ServletConfig servletConfig = new MockServletConfig(SPRING_DISPATCHER_SERVLET, servletContext, initParams); MockJawrSpringServlet servlet = new MockJawrSpringServlet(jawrController, servletConfig); ServletDefinition servletDefinition = new ServletDefinition(servlet, servletConfig); jawrServletDefinitions.add(servletDefinition); } contextLoader.closeWebApplicationContext(servletContext); return jawrServletDefinitions; }
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 .ja va 2 s .c o 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.RootContextLoaderServlet.java
public void registerSubContext(String webAppKey) { // get the sub contexts - servlet context ServletContext ctx = servletContext.getContext(webAppKey); logger.info("Registering subcontext for servlet context: " + ctx.getContextPath()); if (registeredContexts.contains(ctx)) { logger.debug("Context is already registered: " + webAppKey); return;/*from w ww .j a v a 2s . com*/ } ContextLoader loader = new ContextLoader(); ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) loader .initWebApplicationContext(ctx); appCtx.setParent(applicationContext); appCtx.refresh(); ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx); ConfigurableBeanFactory appFactory = appCtx.getBeanFactory(); logger.debug("About to grab Webcontext bean for " + webAppKey); Context webContext = (Context) appCtx.getBean("web.context"); webContext.setCoreBeanFactory(parentFactory); webContext.setClientRegistry(clientRegistry); webContext.setServiceInvoker(globalInvoker); webContext.setScopeResolver(globalResolver); webContext.setMappingStrategy(globalStrategy); WebScope scope = (WebScope) appFactory.getBean("web.scope"); scope.setServer(server); scope.setParent(global); scope.register(); scope.start(); // register the context so we dont try to reinitialize it registeredContexts.add(ctx); }
From source file:org.openmrs.web.filter.update.UpdateFilter.java
/**`` * Do everything to get openmrs going./* w ww. j a va 2s . c o m*/ * * @param servletContext the servletContext from the filterconfig * @see Listener#startOpenmrs(ServletContext) */ private void startOpenmrs(ServletContext servletContext) throws Exception { // start spring // after this point, all errors need to also call: contextLoader.closeWebApplicationContext(event.getServletContext()) // logic copied from org.springframework.web.context.ContextLoaderListener ContextLoader contextLoader = new ContextLoader(); contextLoader.initWebApplicationContext(servletContext); try { WebDaemon.startOpenmrs(servletContext); } catch (Exception exception) { contextLoader.closeWebApplicationContext(servletContext); throw exception; } }