Package org.springframework.web.context

Examples of org.springframework.web.context.ConfigurableWebApplicationContext


public class DefaultSpringLocator implements SpringLocator {

  private static final Logger logger = LoggerFactory.getLogger(DefaultSpringLocator.class);

  public ConfigurableWebApplicationContext getApplicationContext(ServletContext servletContext) {
    ConfigurableWebApplicationContext context = (ConfigurableWebApplicationContext) WebApplicationContextUtils.getWebApplicationContext(servletContext);
    if (context != null) {
      logger.info("Using a web application context: " + context);
      return context;
    }
    if (DefaultSpringLocator.class.getResource("/applicationContext.xml") != null) {
      logger.info("Using an XmlWebApplicationContext, searching for applicationContext.xml");
      XmlWebApplicationContext ctx = new XmlWebApplicationContext();
      ctx.setConfigLocation("classpath:applicationContext.xml");
      return ctx;
    }
    logger.info("No application context found");
    ConfigurableWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.setId("VRaptor");
    return ctx;
  }
View Full Code Here


    verify(servletContext).setAttribute(eq(ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE), isA(WebApplicationContext.class));
  }
 
  @Test
  public void shouldNotIncludeTheApplicationContextOnTheRootApplicationContextParamIfAlreadySet() throws Exception {
    ConfigurableWebApplicationContext ctx = mock(ConfigurableWebApplicationContext.class);

    when(servletContext.getAttributeNames()).thenReturn(enumeration(Collections.<String> emptyList()));
    when(servletContext.getAttribute(ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)).thenReturn(ctx);
     
    defaultExpectations();
View Full Code Here

    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);
View Full Code Here

        }
        // shutdown spring
        Object attr = ctx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
        if (attr != null) {
          // get web application context from the servlet context
          ConfigurableWebApplicationContext applicationContext = (ConfigurableWebApplicationContext) attr;
          ConfigurableBeanFactory factory = applicationContext.getBeanFactory();
          // for (String scope : factory.getRegisteredScopeNames()) {
          // logger.debug("Registered scope: " + scope);
          // }
          try {
            for (String singleton : factory.getSingletonNames()) {
              logger.debug("Registered singleton: {}", singleton);
              factory.destroyScopedBean(singleton);
            }
          } catch (RuntimeException e) {
          }
          factory.destroySingletons();
          applicationContext.close();
        }
      } catch (Throwable e) {
        logger.warn("Exception {}", e);
      } finally {
        super.contextDestroyed(sce);
View Full Code Here

   * @throws BeansException
   */
  protected final ConfigurableWebApplicationContext createWebApplicationContext(
    final WebApplicationContext parent, final WicketFilter filter) throws BeansException
  {
    ConfigurableWebApplicationContext wac = newApplicationContext();
    wac.setParent(parent);
    wac.setServletContext(filter.getFilterConfig().getServletContext());
    wac.setConfigLocation(getContextConfigLocation(filter));

    postProcessWebApplicationContext(wac, filter);
    wac.refresh();

    return wac;
  }
View Full Code Here

    public void testWithSpringContext() throws Exception {
        Container container = EasyMock.createNiceMock(Container.class);
        EasyMock.replay(container);

        ConfigurableWebApplicationContext ac = new XmlWebApplicationContext();
        ServletContext msc = (ServletContext) new MockServletContext();
        msc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac);
        ac.setServletContext(msc);
        ac.setConfigLocations(new String[] {"org/apache/struts2/spring/StrutsSpringObjectFactoryTest-applicationContext.xml"});
        ac.refresh();
        StrutsSpringObjectFactory fac = new StrutsSpringObjectFactory("constructor", null, null, msc, null, container);

        assertEquals(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, fac.getAutowireStrategy());
    }
View Full Code Here

   * @throws BeansException
   */
  protected final ConfigurableWebApplicationContext createWebApplicationContext(
    final WebApplicationContext parent, final WicketFilter filter) throws BeansException
  {
    ConfigurableWebApplicationContext wac = newApplicationContext();
    wac.setParent(parent);
    wac.setServletContext(filter.getFilterConfig().getServletContext());
    wac.setConfigLocation(getContextConfigLocation(filter));

    postProcessWebApplicationContext(wac, filter);
    wac.refresh();

    return wac;
  }
View Full Code Here

   * @throws BeansException
   */
  protected final ConfigurableWebApplicationContext createWebApplicationContext(
    WebApplicationContext parent, WicketFilter filter) throws BeansException
  {
    ConfigurableWebApplicationContext wac = newApplicationContext();
    wac.setParent(parent);
    wac.setServletContext(filter.getFilterConfig().getServletContext());
    wac.setConfigLocation(getContextConfigLocation(filter));

    postProcessWebApplicationContext(wac, filter);
    wac.refresh();

    return wac;
  }
View Full Code Here

    if (this.webApplicationContext != null) {
      // A context instance was injected at construction time -> use it
      wac = this.webApplicationContext;
      if (wac instanceof ConfigurableWebApplicationContext) {
        ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) wac;
        if (!cwac.isActive()) {
          // The context has not yet been refreshed -> provide services such as
          // setting the parent context, setting the application context id, etc
          if (cwac.getParent() == null) {
            // The context instance was injected without an explicit parent -> set
            // the root application context (if any; may be null) as the parent
            cwac.setParent(rootContext);
          }
          configureAndRefreshWebApplicationContext(cwac);
        }
      }
    }
View Full Code Here

      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.setEnvironment(getEnvironment());
    wac.setParent(parent);
    wac.setConfigLocation(getContextConfigLocation());

    configureAndRefreshWebApplicationContext(wac);

    return wac;
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.context.ConfigurableWebApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.