Package org.springframework.web.context

Examples of org.springframework.web.context.ConfigurableWebApplicationContext


      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);

    // Assign the best possible id value.
    ServletContext sc = getServletContext();
    if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
      // Servlet <= 2.4: resort to name specified in web.xml, if any.
      String servletContextName = sc.getServletContextName();
      if (servletContextName != null) {
        wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + servletContextName +
            "." + getServletName());
      }
      else {
        wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + getServletName());
      }
    }
    else {
      // Servlet 2.5's getContextPath available!
      wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + sc.getContextPath() +
          "/" + getServletName());
    }

    wac.setParent(parent);
    wac.setServletContext(getServletContext());
    wac.setServletConfig(getServletConfig());
    wac.setNamespace(getNamespace());
    wac.setConfigLocation(getContextConfigLocation());
    wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener()));

    postProcessWebApplicationContext(wac);
    wac.refresh();

    return wac;
  }
View Full Code Here


     * @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;
    }
View Full Code Here

   *
   * @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();
  }
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

     * @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;
    }
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, null, msc, null, container);

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

   * @param context the application context
   */
  protected void postProcessApplicationContext(ConfigurableApplicationContext context) {
    if (this.webEnvironment) {
      if (context instanceof ConfigurableWebApplicationContext) {
        ConfigurableWebApplicationContext configurableContext = (ConfigurableWebApplicationContext) context;
        if (this.beanNameGenerator != null) {
          configurableContext.getBeanFactory().registerSingleton(
              AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR,
              this.beanNameGenerator);
        }
      }
    }
View Full Code Here

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");
      servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
      return ctx;
    }
    logger.info("No application context found");
    ConfigurableWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.setId("VRaptor");
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx);
    return ctx;
  }
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.