factory.setParent(getApplicationContext()); factory.setServletContext(getServletContext());
context.setParent(parent);
factory.setParent(getApplicationContext()); factory.setServletContext(getServletContext());
/** * Initialize the view bean factory from the XML file. * Synchronized because of access by parallel threads. * @throws BeansException in case of initialization errors */ protected synchronized BeanFactory initFactory() throws BeansException { if (this.cachedFactory != null) { return this.cachedFactory; } ApplicationContext applicationContext = obtainApplicationContext(); Resource actualLocation = this.location; if (actualLocation == null) { actualLocation = applicationContext.getResource(DEFAULT_LOCATION); } // Create child ApplicationContext for views. GenericWebApplicationContext factory = new GenericWebApplicationContext(); factory.setParent(applicationContext); factory.setServletContext(getServletContext()); // Load XML resource with context-aware entity resolver. XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory); reader.setEnvironment(applicationContext.getEnvironment()); reader.setEntityResolver(new ResourceEntityResolver(applicationContext)); reader.loadBeanDefinitions(actualLocation); factory.refresh(); if (isCache()) { this.cachedFactory = factory; } return factory; }
/** * Initialize the view bean factory from the XML file. * Synchronized because of access by parallel threads. * @throws BeansException in case of initialization errors */ protected synchronized BeanFactory initFactory() throws BeansException { if (this.cachedFactory != null) { return this.cachedFactory; } ApplicationContext applicationContext = obtainApplicationContext(); Resource actualLocation = this.location; if (actualLocation == null) { actualLocation = applicationContext.getResource(DEFAULT_LOCATION); } // Create child ApplicationContext for views. GenericWebApplicationContext factory = new GenericWebApplicationContext(); factory.setParent(applicationContext); factory.setServletContext(getServletContext()); // Load XML resource with context-aware entity resolver. XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory); reader.setEnvironment(applicationContext.getEnvironment()); reader.setEntityResolver(new ResourceEntityResolver(applicationContext)); reader.loadBeanDefinitions(actualLocation); factory.refresh(); if (isCache()) { this.cachedFactory = factory; } return factory; }
public class MyContextLoaderListener extends ContextLoaderListener{ protected WebApplicationContext createWebApplicationContext(ServletContext sc, ApplicationContext parent){ ApplicationContext javaSEAppContext = AppContextHolder.getAppContext(); GenericWebApplicationContext context = new GenericWebApplicationContext(servletContext); context.setParent(javaSEAppContext); return context; } }
GenericWebApplicationContext context = new GenericWebApplicationContext(servletContext); context.setParent(rootApplicationContext); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context); xmlReader.loadBeanDefinitions(new ClassPathResource("ApplicationContext/beans.xml")); context.refresh();
//create parent context ApplicationContext xmlContext = new GenericXmlApplicationContext("classpath:/spring-*.xml"); //create mock servlet context MockServletContext mockServletContext = new MockServletContext(); //create web context GenericWebApplicationContext webContext = new GenericWebApplicationContext(mockServletContext); //set attribute mockServletContext.setAttribute(GenericWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext); //set parent context webContext.setParent(xmlContext); //refresh context webContext.refresh();
/** * Performs initialization of the web context binding it to Jetty. * * @throws Exception * in case of an error while starting the Jetty context */ @PostConstruct public void postConstruct() throws Exception { ServletContext servletContext = jettyContext.getServletContext(); GenericWebApplicationContext webCtx = new GenericWebApplicationContext(); webCtx.setServletContext(servletContext); webCtx.setParent(ctx); webCtx.refresh(); servletContext.setAttribute(contextAttribute, webCtx); jettyContext.start(); if (log.isInfoEnabled()) { log.info("| Jetty Web Application Context started!"); } }
public class JettyWrapper extends Server implements ApplicationContextAware { private ApplicationContext appContext; @Override protected void doStart() throws Exception { final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); final GenericWebApplicationContext webApplicationContext = new GenericWebApplicationContext(); webApplicationContext.setServletContext(context.getServletContext()); webApplicationContext.setParent(appContext); context.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext); webApplicationContext.refresh(); DispatcherServlet dispatcherServlet = new DispatcherServlet(); dispatcherServlet.setContextConfigLocation("classpath:servlet-context.xml"); context.addServlet(new ServletHolder(dispatcherServlet), "/*"); context.setContextPath("/"); setHandler(context); super.doStart(); } @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.appContext = applicationContext; }
@Override public Servlet getServletInstance(ServletContext context) { ClassLoader orig = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(module.getClassLoader()); try { final GenericWebApplicationContext mvcContext = new GenericWebApplicationContext(context); mvcContext.setClassLoader(module.getClassLoader()); mvcContext.setServletContext(context); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(mvcContext); xmlReader.setBeanClassLoader(module.getClassLoader()); xmlReader.loadBeanDefinitions(new ClassPathResource(springMvcApplicationContextLocation, module.getClassLoader())); mvcContext.setParent(existingLilyRuntimeSpringContext); mvcContext.refresh(); return new JerseySpringServlet(mvcContext); } finally { Thread.currentThread().setContextClassLoader(orig); } }
@Override public Servlet getServletInstance(ServletContext context) { ClassLoader orig = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(module.getClassLoader()); try { final GenericWebApplicationContext mvcContext = new GenericWebApplicationContext(context); mvcContext.setClassLoader(module.getClassLoader()); mvcContext.setServletContext(context); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(mvcContext); xmlReader.setBeanClassLoader(module.getClassLoader()); xmlReader.loadBeanDefinitions(new ClassPathResource(springMvcApplicationContextLocation, module.getClassLoader())); mvcContext.setParent(existingLilyRuntimeSpringContext); mvcContext.refresh(); DispatcherServlet dispatcherServlet = new DispatcherServlet(mvcContext); dispatcherServlet.setDetectAllHandlerMappings(true); return dispatcherServlet; } finally { Thread.currentThread().setContextClassLoader(orig); } }
factory.setParent(getApplicationContext()); factory.setServletContext(getServletContext());
WebApplicationContextUtils.getRequiredWebApplicationContext(servletConfig.getServletContext()); GenericWebApplicationContext container = new GenericWebApplicationContext(); container.setParent(this.parentContainer); container.setServletContext(this.servletServiceContext); container.refresh();
public void setup(ApplicationContext applicationContext) throws ServletException { MockServletContext servletContext = new MockServletContext(); GenericWebApplicationContext testWebContext = new GenericWebApplicationContext(); testWebContext.setParent(applicationContext); testWebContext.setServletContext(servletContext); servletContext.setAttribute(CONTEXT_NAME, testWebContext); servletContext.setContextPath(CONTEXT_PATH); config = new MockServletConfig(servletContext, "services"); Assert.assertNotNull(config); d.setPublishEvents(false); d.setContextAttribute(CONTEXT_NAME); d.init(config); }
context.setParent(parent);
context.setParent(parent);
container.setParent(this.parentContainer); container.setServletContext(this.servletServiceContext); container.refresh();
/** * Initialize the view bean factory from the XML file. * Synchronized because of access by parallel threads. * @throws BeansException in case of initialization errors */ protected synchronized BeanFactory initFactory() throws BeansException { if (this.cachedFactory != null) { return this.cachedFactory; } Resource actualLocation = this.location; if (actualLocation == null) { actualLocation = getApplicationContext().getResource(DEFAULT_LOCATION); } // Create child ApplicationContext for views. GenericWebApplicationContext factory = new GenericWebApplicationContext(); factory.setParent(getApplicationContext()); factory.setServletContext(getServletContext()); // Load XML resource with context-aware entity resolver. XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory); reader.setEnvironment(getApplicationContext().getEnvironment()); reader.setEntityResolver(new ResourceEntityResolver(getApplicationContext())); reader.loadBeanDefinitions(actualLocation); factory.refresh(); if (isCache()) { this.cachedFactory = factory; } return factory; }
container.setParent(this.parentContainer); container.setServletContext(this.servletServiceContext); container.refresh();