Class ComponentParentContextContextLoaderListener

java.lang.Object
org.springframework.web.context.ContextLoader
org.springframework.web.context.ContextLoaderListener
com.zfabrik.springframework.web.ComponentParentContextContextLoaderListener
All Implemented Interfaces:
EventListener, javax.servlet.ServletContextListener

public class ComponentParentContextContextLoaderListener extends org.springframework.web.context.ContextLoaderListener
This class is useful and recommended when using a Z2 declared Spring application context as a shared parent context for web applications.

It solves two problems:

  1. It addresses the re-use of foreign parent contexts bug described in This bug is severe as it not only leads to re-use of completely unrelated application contexts but also represents a memory leak.
  2. Instead of relying on the non-trivial beanRefContext.xml approach to define a bean factory that in turn retrieves an application context. this implementation retrieves parent contexts simply given a Z2 component name in the context init parameter parentContextComponentName
  3. In order to use, add this to your web.xml file and remove the servlet context listener declaration using Spring's default implementation org.springframework.web.context:
            <listener>
                    <listener-class>com.zfabrik.springframework.web.ComponentParentContextContextLoaderListener</listener-class>
            </listener>
    
            <context-param>
                    <param-name>parentContextComponentName</param-name>
                    <param-value>.. your Z2 component exposing an application context goes here... </param-value>
            </context-param>
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static String
     

    Fields inherited from class org.springframework.web.context.ContextLoader

    CONFIG_LOCATION_PARAM, CONTEXT_CLASS_PARAM, CONTEXT_ID_PARAM, CONTEXT_INITIALIZER_CLASSES_PARAM, GLOBAL_INITIALIZER_CLASSES_PARAM
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.springframework.context.ApplicationContext
    loadParentContext​(javax.servlet.ServletContext servletContext)
     

    Methods inherited from class org.springframework.web.context.ContextLoaderListener

    contextDestroyed, contextInitialized

    Methods inherited from class org.springframework.web.context.ContextLoader

    closeWebApplicationContext, configureAndRefreshWebApplicationContext, createWebApplicationContext, customizeContext, determineContextClass, determineContextInitializerClasses, getCurrentWebApplicationContext, initWebApplicationContext, setContextInitializers

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ComponentParentContextContextLoaderListener

      public ComponentParentContextContextLoaderListener()
  • Method Details

    • loadParentContext

      protected org.springframework.context.ApplicationContext loadParentContext(javax.servlet.ServletContext servletContext)
      Overrides:
      loadParentContext in class org.springframework.web.context.ContextLoader