Spring contextloaderlistener. Java

Source: Internet
Author: User

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 ());
}
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.