This class is the start listener of spring, which must be in the web. xml configuration to modify the listener, the default load WEB-INF/applicationcontext1.xml configuration file, of course, you can customize the configuration file name through the configuration, such as WEB-INF/* context. XML, WEB-INF/spring *. XML "or" WEB-INF/& #42; & #42;/* context. XML is acceptable. If not specified, the/WEB-INF/applicationcontext is loaded by default. XML.
These work mainly through the contextloader. Java class, that is, the Environment Resource loading class, mainly for spring startup initialization.
Package org. springframework. Web. context;
Import javax. servlet. servletcontextevent;
Import javax. servlet. servletcontextlistener;
/**
* Bootstrap listener to start up spring's root {@ link webapplicationcontext }.
* Simply delegates to {@ link contextloader }.
*
* <P> This listener shocould be registered after
* {@ Link org. springframework. Web. util. log4jconfiglistener}
* In <code> Web. xml </code>, if the latter is used.
*
* @ Author Juergen hoeller
* @ Since 172.162.2003
* @ See contextloaderservlet
* @ See org. springframework. Web. util. log4jconfiglistener
*/
Public class contextloaderlistener implements servletcontextlistener {
Private contextloader;
/**
* Initialize the root web application context.
*/
Public void contextinitialized (servletcontextevent event ){
This. contextloader = createcontextloader ();
This. contextloader. initwebapplicationcontext (event. getservletcontext ());
}
/**
* Create the contextloader to use. can be overridden in subclasses.
* @ Return the new contextloader
*/
Protected contextloader createcontextloader (){
Return new contextloader ();
}
/**
* Return the contextloader used by this listener.
* @ Return the current contextloader
*/
Public contextloader getcontextloader (){
Return this. contextloader;
}
/**
* Close the root web application context.
*/
Public void contextdestroyed (servletcontextevent event ){
If (this. contextloader! = NULL ){
This. contextloader. closewebapplicationcontext (event. getservletcontext ());
}
}
}