Configuration in Spring Web. xml

Source: Internet
Author: User

Reprinted blog: http://blog.163.com/zhangke_616/blog/static/191980492007994948206/

In the actual project spring's configuration file Applicationcontext.xml is loaded through spring provided by the loading mechanism, automatically loaded in the container, in the Web project, the configuration file is loaded into the Web container for parsing, currently, Spring provides two loaders for the Web container to load: One is Contextloaderlistener, the other is Contextloaderservlet. The two are functionally identical, but one is based on the newly introduced listener interface implementation in the Servlet2.3 version, and the other is based on the servlet interface, and the following are the timing applications of these two loaders in Web. xml:
The first type:

< Listener > < Listener-class >org.springframework.context.ContextLoaderListener</listener-class>  </listener>

Another type of:

<servlet> <Servlet-name>Context</Servlet-name> <Servlet-class>Org.springframework.context.ContextLoaderServlet</Servlet-class> <Load-on-startup>1</Load-on-startup></servlet>

With the above configuration, the Web container will automatically load Applicationcontext.xml initialization.
If you need to specify a location for the configuration file, you can specify it by Context-param:

< Context-param > < Param-name >contextconfiglocation</param-name><Param-value  >/web-inf/myapplicationcontext.xml</param-value> </ Context-param >

After that, you can

The Webapplicationcontextutils.getwebapplicationcontext method gets a reference to the ApplicationContext in the Web App.

Configuration in Spring Web. XML

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.