List of usage examples for org.springframework.web.context ConfigurableWebApplicationContext setParent
void setParent(@Nullable ApplicationContext parent);
From source file:org.springside.modules.test.spring.SpringWebTestHelper.java
/** * ServletContext?Spring WebApplicationContext. * //www. j a va 2 s .com * @param applicationContext ApplicationContext. */ public static void initWebApplicationContext(MockServletContext servletContext, ApplicationContext applicationContext) { ConfigurableWebApplicationContext wac = new XmlWebApplicationContext(); wac.setParent(applicationContext); wac.setServletContext(servletContext); wac.setConfigLocation(""); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); wac.refresh(); }
From source file:nz.co.senanque.vaadinsupport.application.SpringApplicationLoader.java
public static ApplicationContext loadContext(Application application, HttpServletRequest request) { // Logging//from ww w . ja va 2 s . c om 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; }
From source file:com.ebay.pulsar.metric.server.MetricDispatcherServlet.java
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 + "]"); }/* ww w .j a v a2 s . c o m*/ 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; }
From source file:com.j2trp.test.util.jersey.spi.spring.container.servlet.SpringServlet.java
private ConfigurableApplicationContext getChildContext(String contextConfigLocation) { final ConfigurableWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setParent(getDefaultContext()); ctx.setServletContext(getServletContext()); ctx.setConfigLocation(contextConfigLocation); ctx.refresh();/*from w w w . jav a 2 s. co m*/ return ctx; }
From source file:net.sf.sail.webapp.spring.impl.CustomContextLoader.java
/** * The behaviour of this method is the same as the superclass except for * setting of the config locations.// w w w .j av a 2 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, 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 webApplicationContext = (ConfigurableWebApplicationContext) BeanUtils .instantiateClass(contextClass); webApplicationContext.setParent(parent); 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:com.katsu.dwm.springframework.Loader.java
public void load(File jar, Properties properties) throws MalformedURLException { ConfigurableWebApplicationContext wac = (ConfigurableWebApplicationContext) BeanUtils .instantiateClass(XmlWebApplicationContext.class); //FIXME/*from w w w . ja v a 2s . c om*/ wac.setId("test-context"); wac.setParent(applicationContext); wac.setServletContext(((XmlWebApplicationContext) applicationContext).getServletContext()); //wac.setServletConfig(((XmlWebApplicationContext) applicationContext).getServletConfig()); //wac.setNamespace(((XmlWebApplicationContext) applicationContext).getNamespace()); wac.setConfigLocation(properties.getProperty(LoaderConst.CONTEXT_LOCATION.getValue())); //wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener())); wac.refresh(); wac.getServletContext().setAttribute("test-context", wac); }
From source file:org.sarons.spring4me.web.filter.PageFilter.java
protected ConfigurableWebApplicationContext initPageApplicationContext() { WebApplicationContext root = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); //// w w w. j a v a 2 s. c o m ConfigurableWebApplicationContext wac = (ConfigurableWebApplicationContext) BeanUtils .instantiateClass(contextClass); wac.setParent(root); wac.setServletContext(getServletContext()); wac.setServletConfig(new DelegatingServletConfig(getServletContext())); wac.setNamespace(getNamespace()); wac.setConfigLocation(getWidgetConfigLocation()); wac.refresh(); // return wac; }
From source file:com.workingmouse.webservice.axis.SpringAxisServlet.java
/** * Instantiate the WebApplicationContext for the SpringAxisServlet, 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 w w. j a v a 2 s. c o m*/ * * @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 (LOG.isDebugEnabled()) { LOG.debug("Servlet with name '" + getServletName() + "' 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 servlet with name '" + getServletName() + "': custom WebApplicationContext class [" + getContextClass().getName() + "] is not of type ConfigurableWebApplicationContext"); } ConfigurableWebApplicationContext wac = createContextInstance(); wac.setParent(parent); wac.setServletContext(getServletContext()); wac.setNamespace(getNamespace()); if (this.contextConfigLocation != null) { wac.setConfigLocations(StringUtils.tokenizeToStringArray(this.contextConfigLocation, ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS, true, true)); } wac.refresh(); return wac; }
From source file:com.helpinput.spring.servlet.mvc.EnhanceDispachServlet.java
@Override protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) { ContextHolder.beanRegistIntercpterHolder.register(new UrlInterceptorBeanRegistInterceptor()); Class<?> contextClass = getContextClass(); if (logger.isDebugEnabled()) { logger.debug("Servlet with name '" + getServletName() + "' will try to create custom WebApplicationContext context of class '" + contextClass.getName() + "'" + ", using parent context [" + parent + "]"); }//w w w. j av a 2s . c om 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; if (parent instanceof ConfigurableWebApplicationContext) wac = (ConfigurableWebApplicationContext) parent; else { wac = (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass); wac.setEnvironment(getEnvironment()); wac.setParent(parent); wac.setConfigLocation(getContextConfigLocation()); configureAndRefreshWebApplicationContext(wac); } return wac; }
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;/* w w w. j a v a 2s .c o m*/ } 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); }