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:
jakarta.servlet.ServletContextListener,EventListener
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.xmlapproach 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
FieldsFields 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected org.springframework.context.ApplicationContextloadParentContext(jakarta.servlet.ServletContext servletContext) Methods inherited from class org.springframework.web.context.ContextLoaderListener
contextDestroyed, contextInitializedMethods 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:
-
-
Constructor Details
-
ComponentParentContextContextLoaderListener
public ComponentParentContextContextLoaderListener()
-
-
Method Details
-
loadParentContext
protected org.springframework.context.ApplicationContext loadParentContext(jakarta.servlet.ServletContext servletContext) - Overrides:
loadParentContextin classorg.springframework.web.context.ContextLoader
-