The configuration of spring in Web.xml __web

Source: Internet
Author: User

In the actual project spring's configuration file Applicationcontext.xml is through the loading mechanism provided by spring, in the container that is automatically loaded, in the Web project, the configuration file is loaded into the Web container for resolution, and 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 implementation, and the following are the timing configurations for the two loaders in Web.xml:

First type:
<listener>
<listener-class>org.springframework.context.ContextLoaderListener</listener-class>
</listener>


Another one:
<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 automatically loads Applicationcontext.xml initialization.
If you need to specify the location of 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 pass

The Webapplicationcontextutils.getwebapplicationcontext method gets the ApplicationContext reference in the Web application.


Turn from: http://blog.163.com/zhangke_616/blog/static/191980492007994948206/

Related Article

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.