@Override public void contextInitialized(ServletContextEvent sce) { super.initWebApplicationContext(sce.getServletContext()); }
@Before public void setup() { this.servletContext = new MockServletContext(); this.webAppContext = new AnnotationConfigWebApplicationContext(); this.webAppContext.register(Config.class); this.contextLoader = new ContextLoader(this.webAppContext); this.contextLoader.initWebApplicationContext(this.servletContext); this.configurator = new SpringConfigurator(); }
public void registerSubContext(String webAppKey) { // get the sub contexts - servlet context ServletContext ctx = servletContext.getContext(webAppKey); if (ctx == null) { ctx = servletContext; } 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); }
@Override public WebApplicationContext initWebApplicationContext(ServletContext servletContext) throws IllegalStateException, BeansException { this.servletContext = servletContext; init(); return super.initWebApplicationContext(servletContext); }
@Override public WebApplicationContext initWebApplicationContext(ServletContext servletContext) throws IllegalStateException, BeansException { this.servletContext = servletContext; init(); return super.initWebApplicationContext(servletContext); }
@Test public void updateTargetUrlWithContextLoader() throws Exception { StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class); MockServletContext servletContext = new MockServletContext(); ContextLoader contextLoader = new ContextLoader(wac); contextLoader.initWebApplicationContext(servletContext); try { RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class); wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor); RedirectView rv = new RedirectView(); rv.setUrl("/path"); given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123"); rv.render(new ModelMap(), request, response); verify(mockProcessor).processUrl(request, "/path"); } finally { contextLoader.closeWebApplicationContext(servletContext); } }
/**`` * Do everything to get openmrs going. * * @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; } }
contextLoader.initWebApplicationContext(filterConfig.getServletContext());
public BeanFactory loadBeanFactory() { new ContextLoader().initWebApplicationContext(servletContext); return WebApplicationContextUtils.getWebApplicationContext(servletContext); }
@Override public WebApplicationContext initWebApplicationContext(ServletContext servletContext) throws IllegalStateException, BeansException { this.servletContext = servletContext; init(); return super.initWebApplicationContext(servletContext); }
/** * Initialize the root web application context. */ public void contextInitialized(ServletContextEvent event) { this.contextLoader = createContextLoader(); this.contextLoader.initWebApplicationContext(event.getServletContext()); }
public void init(ServletConfig config) { sc = config.getServletContext(); Logger.log.warn("ReasonableSpringServlet starting up for context " + sc.getRealPath("")); contextLoader = new ContextLoader(); WebApplicationContext wac = contextLoader.initWebApplicationContext(sc); rsacbeanlocator = (RSACBeanLocator) wac .getBean(RSACBeanLocator.RSAC_BEAN_LOCATOR_NAME); }
/** * Initialize the root web application context. */ public void init() throws ServletException { this.contextLoader = createContextLoader(); this.contextLoader.initWebApplicationContext(getServletContext()); }
@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); }
public synchronized void refresh() { ContextLoader loader = new BootstrappedContextLoader(); // if we have an existing spring context, ensure we close it properly ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); if (ctx != null) { loader.closeWebApplicationContext(getServletContext()); } loader.initWebApplicationContext(getServletContext()); if (getApplicationContext() == null) { setApplicationContext(WebApplicationContextUtils.getWebApplicationContext(getServletContext())); } contextReloaded(); } }
/** * Crea e restituisce il Contesto dell'Applicazione. * * @param srvCtx Il Contesto della Servlet. * @return Il Contesto dell'Applicazione. */ public ApplicationContext createApplicationContext(ServletContext srvCtx) { this.createNamingContext(); XmlWebApplicationContext applicationContext = new XmlWebApplicationContext(); applicationContext.setConfigLocations(this.getSpringConfigFilePaths()); applicationContext.setServletContext(srvCtx); ContextLoader contextLoader = new ContextLoader(applicationContext); contextLoader.initWebApplicationContext(srvCtx); applicationContext.refresh(); return applicationContext; }