Package org.springframework.web.context

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


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

    postProcessWebApplicationContext(wac);
    wac.refresh();

    return wac;
  }
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

          "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());
    wac.setConfigLocation(getContextConfigLocation());
    wac.addApplicationListener(new SourceFilteringListener(wac, this));

    postProcessWebApplicationContext(wac);
    wac.refresh();

    return wac;
  }
View Full Code Here

      }
      System.setProperty("red5.root", root);
      logger.info("Setting Red5 root to " + root);

      Class contextClass = org.springframework.web.context.support.XmlWebApplicationContext.class;
      ConfigurableWebApplicationContext applicationContext = (ConfigurableWebApplicationContext) BeanUtils
          .instantiateClass(contextClass);

      String[] strArray = servletContext.getInitParameter(
          ContextLoader.CONFIG_LOCATION_PARAM).split("[,\\s]");
      logger.info("Config location files: " + strArray.length);
      applicationContext.setConfigLocations(strArray);
      applicationContext.setServletContext(servletContext);
      applicationContext.refresh();

      // set web application context as an attribute of the servlet
      // context so that it may be located via Springs
      // WebApplicationContextUtils
      servletContext
          .setAttribute(
              WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
              applicationContext);

      ConfigurableBeanFactory factory = applicationContext
          .getBeanFactory();
      // register default
      // add the context to the parent
      factory.registerSingleton("default.context", applicationContext);
View Full Code Here

      }
      // shutdown jmx
      JMXAgent.shutdown();
      // shutdown spring
      // get web application context from the servlet context
      ConfigurableWebApplicationContext applicationContext = (ConfigurableWebApplicationContext) servletContext
          .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
      ConfigurableBeanFactory factory = applicationContext
          .getBeanFactory();
      if (factory.containsSingleton("default.context")) {
        for (String scope : factory.getRegisteredScopeNames()) {
          logger.debug("Registered scope: " + scope);
        }
        for (String singleton : factory.getSingletonNames()) {
          logger.debug("Registered singleton: " + singleton);
          // factory.destroyScopedBean(singleton);
        }
        factory.destroySingletons();
      }
      servletContext
          .removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
      applicationContext.close();
      // http://jakarta.apache.org/commons/logging/guide.html#Classloader_and_Memory_Management
      // http://wiki.apache.org/jakarta-commons/Logging/UndeployMemoryLeak?action=print
      // LogFactory.release(Thread.currentThread().getContextClassLoader());
    } catch (Throwable e) {
      // may get a java.lang.StackOverflowError when shutting appcontext
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();
          ctx.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
          applicationContext.close();
        }
        getContextLoader().closeWebApplicationContext(ctx);
//        org.apache.commons.logging.LogFactory.releaseAll();
//        org.apache.log4j.LogManager.getLoggerRepository().shutdown();
//        org.apache.log4j.LogManager.shutdown();
View Full Code Here

      return;
    }

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

          ctx
              .removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
          applicationContext.close();
        }
        instance.getContextLoader().closeWebApplicationContext(ctx);
      } catch (Throwable e) {
        e.printStackTrace();
      } finally {
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.