Package com.zfabrik.springframework.web
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:
- 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.
- 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 parameterparentContextComponentName
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 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
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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
-
Field Details
-
PARENT_CONTEXT_COMPONENT_NAME
- See Also:
- Constant Field Values
-
-
Constructor Details
-
ComponentParentContextContextLoaderListener
public ComponentParentContextContextLoaderListener()
-
-
Method Details
-
loadParentContext
protected org.springframework.context.ApplicationContext loadParentContext(javax.servlet.ServletContext servletContext)- Overrides:
loadParentContext
in classorg.springframework.web.context.ContextLoader
-