Examples of ConfigurableWebApplicationContext


Examples of org.springframework.web.context.ConfigurableWebApplicationContext

          "Fatal initialization error in ContextLoaderPlugIn for Struts ActionServlet '" + getServletName() +
          "', module '" + getModulePrefix() + "': custom WebApplicationContext class [" +
          getContextClass().getName() + "] is not of type ConfigurableWebApplicationContext");
    }

    ConfigurableWebApplicationContext wac =
        (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(getContextClass());
    wac.setParent(parent);
    wac.setServletContext(getServletContext());
    wac.setNamespace(getNamespace());
    if (getContextConfigLocation() != null) {
      wac.setConfigLocations(
          StringUtils.tokenizeToStringArray(
              getContextConfigLocation(), ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));
    }
    wac.addBeanFactoryPostProcessor(
        new BeanFactoryPostProcessor() {
          public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
            beanFactory.addBeanPostProcessor(new ActionServletAwareProcessor(getActionServlet()));
            beanFactory.ignoreDependencyType(ActionServlet.class);
          }
        }
    );

    wac.refresh();
    return wac;
  }
View Full Code Here

Examples of org.springframework.web.context.ConfigurableWebApplicationContext

    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

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

    wac.setParent(parent);
    wac.setConfigLocation(getContextConfigLocation());

    configureAndRefreshWebApplicationContext(wac);

    return wac;
  }
View Full Code Here

Examples of org.springframework.web.context.ConfigurableWebApplicationContext

          "Fatal initialization error in ContextLoaderPlugIn for Struts ActionServlet '" + getServletName() +
          "', module '" + getModulePrefix() + "': custom WebApplicationContext class [" +
          getContextClass().getName() + "] is not of type ConfigurableWebApplicationContext");
    }

    ConfigurableWebApplicationContext wac =
        (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(getContextClass());
    wac.setParent(parent);
    wac.setServletContext(getServletContext());
    wac.setNamespace(getNamespace());
    if (getContextConfigLocation() != null) {
      wac.setConfigLocations(
          StringUtils.tokenizeToStringArray(
              getContextConfigLocation(), ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));
    }
    wac.addBeanFactoryPostProcessor(
        new BeanFactoryPostProcessor() {
          public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
            beanFactory.addBeanPostProcessor(new ActionServletAwareProcessor(getActionServlet()));
            beanFactory.ignoreDependencyType(ActionServlet.class);
          }
        }
    );

    wac.refresh();
    return wac;
  }
View Full Code Here

Examples of org.springframework.web.context.ConfigurableWebApplicationContext

          "Fatal initialization error in servlet with name '" + getServletName() +
          "': custom WebApplicationContext class [" + getContextClass().getName() +
          "] is not of type ConfigurableWebApplicationContext");
    }

    ConfigurableWebApplicationContext wac =
        (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(getContextClass());
    wac.setParent(parent);
    wac.setServletContext(getServletContext());
    wac.setServletConfig(getServletConfig());
    wac.setNamespace(getNamespace());
    if (getContextConfigLocation() != null) {
      wac.setConfigLocations(
          StringUtils.tokenizeToStringArray(
              getContextConfigLocation(), ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));
    }
    wac.addApplicationListener(new SourceFilteringListener(wac, this));

    postProcessWebApplicationContext(wac);
    wac.refresh();

    return wac;
  }
View Full Code Here

Examples of org.springframework.web.context.ConfigurableWebApplicationContext

    assertEquals("Correct message", "test message", pc.getAttribute("testvar"));
  }
 
  public void testNullMessageSource() throws JspException {
    PageContext pc = createPageContext();
    ConfigurableWebApplicationContext ctx = (ConfigurableWebApplicationContext)
        RequestContextUtils.getWebApplicationContext(pc.getRequest(), pc.getServletContext());
    ctx.close();

    MessageTag tag = new MessageTag();
    tag.setPageContext(pc);
    tag.setCode("test");
    tag.setVar("testvar2");
View Full Code Here

Examples of org.springframework.web.context.ConfigurableWebApplicationContext

    public synchronized void registerShutdownHook() {
        this.appContext.registerShutdownHook();
    }

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

Examples of org.springframework.web.context.ConfigurableWebApplicationContext

    }

    public void testWithSpringContext() throws Exception {
       

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

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

Examples of org.springframework.web.context.ConfigurableWebApplicationContext

  /**
   * Configures Spring.
   */
  private void configureSpring(ServletContextEvent arg0) {
    ConfigurableWebApplicationContext ctx = new XmlWebApplicationContext();
    ctx.setServletContext(arg0.getServletContext());

    URL defaultConfig = YFacesStartupListener.class.getResource(DEFAULT_YFACES_CTX);
    String[] configs = new String[] { defaultConfig.toExternalForm() };

    try {
      String yfacesCtx = arg0.getServletContext().getInitParameter(PARAM_YFACES_CTX);
      if (yfacesCtx != null) {
        URL customConfig = arg0.getServletContext().getResource(yfacesCtx);
        configs = new String[] { configs[0], customConfig.toExternalForm() };
      }
      log.debug("Using spring configuration:" + Arrays.asList(configs));
      ctx.setConfigLocations(configs);
      ctx.refresh();
      new YApplicationContext(ctx);

    } catch (MalformedURLException e) {
      e.printStackTrace();
    }
View Full Code Here

Examples of org.springframework.web.context.ConfigurableWebApplicationContext

{
    @Test
    public void load_application_context_externally()
    {
        ServletContext servletContext = mockServletContext();
        ConfigurableWebApplicationContext ac = newMock(ConfigurableWebApplicationContext.class);
        Runnable fred = mockRunnable();
        Runnable barney = mockRunnable();

        ServiceBuilderResources resources = mockServiceBuilderResources();

        train_getInitParameter(servletContext, SpringConstants.USE_EXTERNAL_SPRING_CONTEXT, "true");

        train_getAttribute(servletContext, WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac);

        // Simulate barney as a factory bean.

        expect(ac.getBeanNamesForType(Object.class)).andReturn(new String[] {"fred", "&barney"});
        expect(ac.getParentBeanFactory()).andReturn(null);

        replay();

        SpringModuleDef moduleDef = new SpringModuleDef(servletContext);

        ServiceDef serviceDef = moduleDef.getServiceDef(SpringModuleDef.SERVICE_ID);

        ObjectCreator serviceCreator = serviceDef.createServiceCreator(resources);

        assertSame(serviceCreator.createObject(), ac);

        verify();

        // Now, let's test for some of the services.

        ServiceDef sd = moduleDef.getServiceDef("ApplicationContext");

        assertEquals(sd.getServiceInterface(), ac.getClass());
        assertEquals(sd.createServiceCreator(null).toString(),
                     "<ObjectCreator for externally configured Spring ApplicationContext>");

        expect((Class)ac.getType("fred")).andReturn(Runnable.class);
        expect(ac.getBean("fred")).andReturn(fred);


        sd = moduleDef.getServiceDef("fred");

        replay();

        assertEquals(sd.getServiceId(), "fred");
        assertEquals(sd.getServiceInterface(), Runnable.class);
        assertEquals(sd.getServiceScope(), ScopeConstants.DEFAULT);
        assertSame(sd.createServiceCreator(null).createObject(), fred);
        assertTrue(sd.getMarkers().isEmpty());
        assertFalse(sd.isEagerLoad());
        assertEquals(sd.createServiceCreator(null).toString(), "ObjectCreator<Spring Bean 'fred'>");

        verify();

        expect((Class)ac.getType("barney")).andReturn(Runnable.class);
        expect(ac.getBean("barney")).andReturn(barney);

        replay();

        sd = moduleDef.getServiceDef("barney");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.