Package org.springframework.web.context.support

Examples of org.springframework.web.context.support.XmlWebApplicationContext


  private ConfigurableWebApplicationContext wac;

  @Before
  public void setUp() throws Exception {
    MockServletContext sc = new MockServletContext("");
    wac = new XmlWebApplicationContext();
    wac.setServletContext(sc);
    wac.setConfigLocations(new String[] {CONF});
    wac.refresh();
    hm = (HandlerMapping) wac.getBean("urlMapping");
  }
View Full Code Here


  private ConfigurableWebApplicationContext root;

  @Override
  protected ConfigurableApplicationContext createContext() throws Exception {
    InitAndIB.constructed = false;
    root = new XmlWebApplicationContext();
    root.getEnvironment().addActiveProfile("rootProfile1");
    MockServletContext sc = new MockServletContext("");
    root.setServletContext(sc);
    root.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/applicationContext.xml"});
    root.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
      @Override
      public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
        beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
          @Override
          @SuppressWarnings("unchecked")
          public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
            if (bean instanceof TestBean) {
              ((TestBean) bean).getFriends().add("myFriend");
            }
            return bean;
          }
          @Override
          public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
            return bean;
          }
        });
      }
    });
    root.refresh();
    XmlWebApplicationContext wac = new XmlWebApplicationContext();
    wac.getEnvironment().addActiveProfile("wacProfile1");
    wac.setParent(root);
    wac.setServletContext(sc);
    wac.setNamespace("test-servlet");
    wac.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/test-servlet.xml"});
    wac.refresh();
    return wac;
  }
View Full Code Here

  private HandlerMapping hm4;

  @Override
  public void setUp() throws Exception {
    MockServletContext sc = new MockServletContext("");
    this.wac = new XmlWebApplicationContext();
    this.wac.setServletContext(sc);
    this.wac.setConfigLocations(new String[] {LOCATION});
    this.wac.refresh();
    this.hm = (HandlerMapping) this.wac.getBean("mapping");
    this.hm2 = (HandlerMapping) this.wac.getBean("mapping2");
View Full Code Here

    // get the configured adapters from Spring
    WebApplicationContext parent = WebApplicationContextUtils
      .getRequiredWebApplicationContext(getServletContext());

    ConfigurableWebApplicationContext wac = new XmlWebApplicationContext();
    wac.setParent(parent);
    wac.setServletContext(getServletContext());
    wac.setServletConfig(getServletConfig());
    wac.setNamespace(servletConfig.getServletName() + "-servlet");
    wac.refresh();

    Set<SpringBinding> bindings = new LinkedHashSet<SpringBinding>();

    // backward compatibility. recognize all bindings
    Map m = wac.getBeansOfType(SpringBindingList.class);
    for (SpringBindingList sbl : (Collection<SpringBindingList>) m.values()) {
      bindings.addAll(sbl.getBindings());
    }

    bindings.addAll(wac.getBeansOfType(SpringBinding.class).values());

    // create adapters
    ServletAdapterList l = new ServletAdapterList();
    for (SpringBinding binding : bindings) {
      binding.create(l);
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

   *
   * @return application context instance
   */
  protected ConfigurableWebApplicationContext newApplicationContext()
  {
    return new XmlWebApplicationContext();
  }
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

    protected static SessionFactory sessionFactory;
   
   
    @BeforeClass
    public static void initAppContext() throws Exception {
        ctx = new XmlWebApplicationContext() {
            public String[] getConfigLocations() {
                return new String[]{
                    "file:src/main/resources/applicationContext.xml",
                    "file:src/test/resources/applicationContext-test.xml"};
            }
View Full Code Here

    HttpSession httpSession = request.getSession();
    ServletContext servletContext = httpSession.getServletContext();
    HDIVUtil.setHttpServletRequest(request);

    // Init Spring Context
    XmlWebApplicationContext webApplicationContext = new XmlWebApplicationContext();
    webApplicationContext.setServletContext(servletContext);
    webApplicationContext.setConfigLocations(files);
    servletContext
        .setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);
    // Create beans
    webApplicationContext.refresh();

    this.applicationContext = webApplicationContext;

    // Initialize config
    this.config = (HDIVConfig) this.applicationContext.getBean(HDIVConfig.class);
View Full Code Here

TOP

Related Classes of org.springframework.web.context.support.XmlWebApplicationContext

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.