public class ContextLoaderListener extends ContextLoader implements ServletContextListener
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 3.0+ environments.
See WebApplicationInitializer
for usage examples.
ContextLoader.setContextInitializers(org.springframework.context.ApplicationContextInitializer<?>...)
,
WebApplicationInitializer
CONFIG_LOCATION_PARAM, CONTEXT_CLASS_PARAM, CONTEXT_ID_PARAM, CONTEXT_INITIALIZER_CLASSES_PARAM, GLOBAL_INITIALIZER_CLASSES_PARAM
Constructor and Description |
---|
ContextLoaderListener()
Create a new
ContextLoaderListener that will create a web application
context based on the "contextClass" and "contextConfigLocation" servlet
context-params. |
ContextLoaderListener(WebApplicationContext context)
Create a new
ContextLoaderListener with the given application context. |
Modifier and Type | Method and Description |
---|---|
void |
contextDestroyed(ServletContextEvent event)
Close the root web application context.
|
void |
contextInitialized(ServletContextEvent event)
Initialize the root web application context.
|
closeWebApplicationContext, configureAndRefreshWebApplicationContext, createWebApplicationContext, customizeContext, determineContextClass, determineContextInitializerClasses, getCurrentWebApplicationContext, initWebApplicationContext, loadParentContext, setContextInitializers
public ContextLoaderListener()
ContextLoaderListener
that will create a web application
context based on the "contextClass" and "contextConfigLocation" servlet
context-params. See ContextLoader
superclass documentation for details on
default values for each.
This constructor is typically used when declaring ContextLoaderListener
as a <listener>
within web.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_ATTRIBUTE
and the Spring application context will be closed when the contextDestroyed(javax.servlet.ServletContextEvent)
lifecycle method is invoked on this listener.
public ContextLoaderListener(WebApplicationContext context)
ContextLoaderListener
with the given application context. This
constructor is useful in Servlet 3.0+ environments where instance-based
registration of listeners is possible through the ServletContext.addListener(java.lang.String)
API.
The context may or may not yet be refreshed. If it
(a) is an implementation of ConfigurableWebApplicationContext
and
(b) has not already been refreshed (the recommended approach),
then the following will occur:
ServletContext
and ServletConfig
objects will be delegated to
the application contextContextLoader.customizeContext(javax.servlet.ServletContext, org.springframework.web.context.ConfigurableWebApplicationContext)
will be calledApplicationContextInitializer org.springframework.context.ApplicationContextInitializer ApplicationContextInitializers
specified through the "contextInitializerClasses" init-param will be applied.refresh()
will be calledConfigurableWebApplicationContext
, 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 WebApplicationInitializer
for usage examples.
In any case, the given application context will be registered into the
ServletContext under the attribute name WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
and the Spring
application context will be closed when the contextDestroyed(javax.servlet.ServletContextEvent)
lifecycle
method is invoked on this listener.
context
- the application context to managecontextInitialized(ServletContextEvent)
,
contextDestroyed(ServletContextEvent)
public void contextInitialized(ServletContextEvent event)
contextInitialized
in interface ServletContextListener
event
- the ServletContextEvent containing the ServletContext
that is being initializedpublic void contextDestroyed(ServletContextEvent event)
contextDestroyed
in interface ServletContextListener
event
- the ServletContextEvent containing the ServletContext
that is being destroyed