类 ContextLoaderListener
- java.lang.Object
- org.springframework.web.context.ContextLoader
- org.springframework.web.context.ContextLoaderListener
- 所有已实现的接口:
EventListener
,ServletContextListener
public class ContextLoaderListener extends ContextLoader implements ServletContextListener
Bootstrap listener to start up and shut down Spring's rootWebApplicationContext
. Simply delegates toContextLoader
as well as toContextCleanupListener
.This listener should be registered after
Log4jConfigListener
inweb.xml
, if the latter is used.As of Spring 3.1,
ContextLoaderListener
supports injecting the root web application context via theContextLoaderListener(WebApplicationContext)
constructor, allowing for programmatic configuration in Servlet 3.0+ environments. SeeWebApplicationInitializer
for usage examples.- 从以下版本开始:
- 17.02.2003
- 作者:
- Juergen Hoeller, Chris Beams
- 另请参阅:
ContextLoader.setContextInitializers(org.springframework.context.ApplicationContextInitializer<?>...)
,WebApplicationInitializer
,Log4jConfigListener
字段概要
从类继承的字段 org.springframework.web.context.ContextLoader
CONFIG_LOCATION_PARAM, CONTEXT_CLASS_PARAM, CONTEXT_ID_PARAM, CONTEXT_INITIALIZER_CLASSES_PARAM, GLOBAL_INITIALIZER_CLASSES_PARAM, LOCATOR_FACTORY_KEY_PARAM, LOCATOR_FACTORY_SELECTOR_PARAM
构造器概要
构造器 构造器 说明 ContextLoaderListener()
Create a newContextLoaderListener
that will create a web application context based on the "contextClass" and "contextConfigLocation" servlet context-params.ContextLoaderListener(WebApplicationContext context)
Create a newContextLoaderListener
with the given application context.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
contextDestroyed(ServletContextEvent event)
Close the root web application context.void
contextInitialized(ServletContextEvent event)
Initialize the root web application context.从类继承的方法 org.springframework.web.context.ContextLoader
closeWebApplicationContext, configureAndRefreshWebApplicationContext, createWebApplicationContext, customizeContext, determineContextClass, determineContextInitializerClasses, getCurrentWebApplicationContext, initWebApplicationContext, loadParentContext, setContextInitializers
构造器详细资料
ContextLoaderListener
public ContextLoaderListener()
Create a newContextLoaderListener
that will create a web application context based on the "contextClass" and "contextConfigLocation" servlet context-params. SeeContextLoader
superclass documentation for details on default values for each.This constructor is typically used when declaring
ContextLoaderListener
as 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_ATTRIBUTE
and the Spring application context will be closed when thecontextDestroyed(javax.servlet.ServletContextEvent)
lifecycle method is invoked on this listener.
ContextLoaderListener
public ContextLoaderListener(WebApplicationContext context)
Create a newContextLoaderListener
with the given application context. This constructor is useful in Servlet 3.0+ environments 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
ConfigurableWebApplicationContext
and (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
ServletContext
andServletConfig
objects will be delegated to the application contextContextLoader.customizeContext(javax.servlet.ServletContext, org.springframework.web.context.ConfigurableWebApplicationContext)
will be called- Any
ApplicationContextInitializer
s specified 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
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 thecontextDestroyed(javax.servlet.ServletContextEvent)
lifecycle method is invoked on this listener.- 参数:
context
- the application context to manage- 另请参阅:
contextInitialized(ServletContextEvent)
,contextDestroyed(ServletContextEvent)
方法详细资料
contextInitialized
public void contextInitialized(ServletContextEvent event)
Initialize the root web application context.- 指定者:
contextInitialized
在接口中ServletContextListener
contextDestroyed
public void contextDestroyed(ServletContextEvent event)
Close the root web application context.- 指定者:
contextDestroyed
在接口中ServletContextListener