Class ContextLoaderListener
- All Implemented Interfaces:
ServletContextListener,EventListener
WebApplicationContext.
Simply delegates to ContextLoader as well as to ContextCleanupListener.
As of Spring 3.1, ContextLoaderListener supports injecting the root web
application context via the ContextLoaderListener(WebApplicationContext)
constructor, allowing for programmatic configuration in Servlet initializers.
See WebApplicationInitializer for usage examples.
- Since:
- 17.02.2003
- Author:
- Juergen Hoeller, Chris Beams
- See Also:
-
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
ConstructorsConstructorDescriptionCreate a newContextLoaderListenerthat will create a web application context based on the "contextClass" and "contextConfigLocation" servlet context-params.Create a newContextLoaderListenerwith the given application context. -
Method Summary
Modifier and TypeMethodDescriptionvoidClose the root web application context.voidInitialize the root web application context.Methods inherited from class org.springframework.web.context.ContextLoader
closeWebApplicationContext, configureAndRefreshWebApplicationContext, createWebApplicationContext, customizeContext, determineContextClass, determineContextInitializerClasses, getCurrentWebApplicationContext, initWebApplicationContext, loadParentContext, setContextInitializers
-
Constructor Details
-
ContextLoaderListener
public ContextLoaderListener()Create a newContextLoaderListenerthat will create a web application context based on the "contextClass" and "contextConfigLocation" servlet context-params. SeeContextLoadersuperclass documentation for details on default values for each.This constructor is typically used when declaring
ContextLoaderListeneras a<listener>withinweb.xml, where a no-arg constructor is required.The created application context will be registered into the ServletContext under the attribute name
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTEand the Spring application context will be closed when thecontextDestroyed(jakarta.servlet.ServletContextEvent)lifecycle method is invoked on this listener. -
ContextLoaderListener
Create a newContextLoaderListenerwith the given application context. This constructor is useful in Servlet initializers where instance-based registration of listeners is possible through theServletContext.addListener(java.lang.String)API.The context may or may not yet be refreshed. If it (a) is an implementation of
ConfigurableWebApplicationContextand (b) has not already been refreshed (the recommended approach), then the following will occur:- If the given context has not already been assigned an id, one will be assigned to it
ServletContextandServletConfigobjects will be delegated to the application contextContextLoader.customizeContext(jakarta.servlet.ServletContext, org.springframework.web.context.ConfigurableWebApplicationContext)will be called- Any
ApplicationContextInitializer org.springframework.context.ApplicationContextInitializer ApplicationContextInitializersspecified through the "contextInitializerClasses" init-param will be applied. refresh()will be called
ConfigurableWebApplicationContext, none of the above will occur under the assumption that the user has performed these actions (or not) per his or her specific needs.See
WebApplicationInitializerfor usage examples.In any case, the given application context will be registered into the ServletContext under the attribute name
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTEand the Spring application context will be closed when thecontextDestroyed(jakarta.servlet.ServletContextEvent)lifecycle method is invoked on this listener.- Parameters:
context- the application context to manage- See Also:
-
-
Method Details
-
contextInitialized
Initialize the root web application context.- Specified by:
contextInitializedin interfaceServletContextListener
-
contextDestroyed
Close the root web application context.- Specified by:
contextDestroyedin interfaceServletContextListener
-