cwac.setParent(parent);
cwac.setParent(parent);
wac.setParent(parent); String configLocation = getContextConfigLocation(); if (configLocation != null) {
cwac.setParent(rootContext);
wac.setParent(parent); String configLocation = getContextConfigLocation(); if (configLocation != null) {
cwac.setParent(rootContext);
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); }
protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) { Class<?> contextClass = getContextClass(); if (this.logger.isDebugEnabled()) { this.logger.debug("Servlet with name '" + getServletName() + "' will try to create custom WebApplicationContext context of class '" + contextClass.getName() + "'" + ", using parent context [" + parent + "]"); } if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) { throw new ApplicationContextException( "Fatal initialization error in servlet with name '" + getServletName() + "': custom WebApplicationContext class [" + contextClass.getName() + "] is not of type ConfigurableWebApplicationContext"); } ConfigurableWebApplicationContext wac = (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass); wac.setParent(parent); if (wac.getParent() == null) { ApplicationContext rootContext = (ApplicationContext) getServletContext().getAttribute("JetStreamRoot"); wac.setParent(rootContext); } wac.setConfigLocation(getContextConfigLocation()); configureAndRefreshWebApplicationContext(wac); return wac; } }
/** * Set a parent context before the application context is "refreshed". * * <p>The parent context is expected to have be fully initialized. * * <p>Caution: this method is potentially subject to change depending * on the outcome of SPR-5243 and SPR-5613. */ public ContextMockMvcBuilder setParentContext(ApplicationContext parentContext) { this.webAppContext.setParent(parentContext); return this; } }
@Override public synchronized void setParent(ApplicationContext context) { this.appContext.setParent(context); }
public static ApplicationContext loadContext(Application application, HttpServletRequest request) { // Logging log.info("loading application context for Vaadin application " + application.getClass().getSimpleName()); CURRENT_APPLICATION.set(application); // Find the application context associated with the servlet; it will be the parent ServletContext servletContext; try { // getServletContext() is a servlet AIP 3.0 method, so don't freak out if it's not there servletContext = (ServletContext)HttpServletRequest.class.getMethod("getServletContext").invoke(request); } catch (Exception e) { servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext(); } WebApplicationContext parent = WebApplicationContextUtils.getWebApplicationContext(servletContext); // Create and configure a new application context for this Application instance ConfigurableWebApplicationContext context = new XmlWebApplicationContext(); context.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + servletContext.getContextPath() + "/" + application.getClass().getSimpleName() + "-" + UNIQUE_INDEX.incrementAndGet()); context.setParent(parent); context.setServletContext(servletContext); //context.setServletConfig(??); context.setNamespace(application.getClass().getSimpleName()); // Refresh context context.refresh(); CURRENT_APPLICATION.set(null); return context; } public Application get()
public synchronized void reload() { ConfigurableWebApplicationContext newAppContext = null; try { newAppContext = BeanUtils.instantiateClass(XmlWebApplicationContext.class); } catch (BeanInstantiationException e) { throw new RuntimeException("Can't create Spring application context.", e); } newAppContext.setParent(this.appContext.getParent()); newAppContext.setServletContext(this.appContext.getServletContext()); this.appContext.close(); this.appContext = newAppContext; this.appContext.refresh(); }
wac.setParent(parent); wac.setConfigLocation(contextConfigLocation);
sessionContext.setParent(appContext); sessionContext.setServletContext(servletContext); String configLocation = servletContext.getInitParameter(SESSION_CONFIG_LOCATION_PARAM);
/** * Instantiate the root WebApplicationContext for this loader, either the * default context class or a custom context class if specified. * <p>This implementation expects custom contexts to implement * ConfigurableWebApplicationContext. Can be overridden in subclasses. * @param servletContext current servlet context * @param parent the parent ApplicationContext to use, or <code>null</code> if none * @return the root WebApplicationContext * @throws BeansException if the context couldn't be initialized * @see ConfigurableWebApplicationContext */ protected WebApplicationContext createWebApplicationContext( ServletContext servletContext, ApplicationContext parent) 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 wac = (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass); wac.setParent(parent); wac.setServletContext(servletContext); String configLocation = servletContext.getInitParameter(CONFIG_LOCATION_PARAM); if (configLocation != null) { wac.setConfigLocations(StringUtils.tokenizeToStringArray(configLocation, ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS)); } wac.refresh(); return wac; }
@Override protected WebApplicationContext createWebApplicationContext( ServletContext servletContext, ApplicationContext parent) throws BeansException { ConfigurableWebApplicationContext wac = new CompilationAwareXmlWebApplicationContext(); wac.setParent(parent); wac.setServletContext(servletContext); wac.setConfigLocation(servletContext.getInitParameter(CONFIG_LOCATION_PARAM)); customizeContext(servletContext, wac); wac.refresh(); //we now init the scripting system Class contextClass = determineContextClass(servletContext); if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) { throw new ApplicationContextException("Custom context class [" + contextClass.getName() + "] is not of type [" + ConfigurableWebApplicationContext.class.getName() + "]"); } return wac; }
@Override protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) { if (this.logger.isDebugEnabled()) { this.logger.debug("Servlet with name '" + getServletName() + "' will try to create custom WebApplicationContext context of class '" + CubaXmlWebApplicationContext.class.getName() + "'" + ", using parent context [" + parent + "]"); } ConfigurableWebApplicationContext wac = new CubaXmlWebApplicationContext() { @Override protected ResourcePatternResolver getResourcePatternResolver() { if (dependencyJars == null || dependencyJars.isEmpty()) { throw new RuntimeException("No JARs defined for the 'web' block. " + "Please check that web.dependencies file exists in WEB-INF directory."); } return new SingleAppResourcePatternResolver(this, dependencyJars); } }; wac.setEnvironment(getEnvironment()); wac.setParent(parent); wac.setConfigLocation(getContextConfigLocation()); configureAndRefreshWebApplicationContext(wac); return wac; } }
@Override protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) { if (this.logger.isDebugEnabled()) { this.logger.debug("Servlet with name '" + getServletName() + "' will try to create custom WebApplicationContext context of class '" + CubaXmlWebApplicationContext.class.getName() + "'" + ", using parent context [" + parent + "]"); } ConfigurableWebApplicationContext wac = new CubaXmlWebApplicationContext() { @Override protected ResourcePatternResolver getResourcePatternResolver() { if (dependencyJars == null || dependencyJars.isEmpty()) { throw new RuntimeException("No JARs defined for the 'web' block. " + "Please check that web.dependencies file exists in WEB-INF directory."); } return new SingleAppResourcePatternResolver(this, dependencyJars); } }; wac.setEnvironment(getEnvironment()); wac.setParent(parent); wac.setConfigLocation(getContextConfigLocation()); configureAndRefreshWebApplicationContext(wac); return wac; } }
/** * Creates and initializes a new {@link WebApplicationContext}, with the given context as the * parent. Based on the logic in {@link FrameworkServlet#createWebApplicationContext} * * @param parent * parent application context * @param filter * wicket filter * @return instance of web application context * @throws BeansException */ protected final ConfigurableWebApplicationContext createWebApplicationContext( final WebApplicationContext parent, final WicketFilter filter) throws BeansException { webApplicationContext = newApplicationContext(); webApplicationContext.setParent(parent); webApplicationContext.setServletContext(filter.getFilterConfig().getServletContext()); webApplicationContext.setConfigLocation(getContextConfigLocation(filter)); postProcessWebApplicationContext(webApplicationContext, filter); webApplicationContext.refresh(); return webApplicationContext; }
/** * Get the child application context. * <p> * The child application context is created as a child of the default * application context obtained from {@link #getDefaultContext() }. * * @param contextConfigLocation the location of the child application * context. * @return the child application context. */ protected ConfigurableApplicationContext getChildContext(String contextConfigLocation) { final ConfigurableWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setParent(getDefaultContext()); ctx.setServletContext(getServletContext()); ctx.setConfigLocation(contextConfigLocation); ctx.refresh(); return ctx; } }