ApplicationContext Instantiation of Web projects

Source: Internet
Author: User

Spring provides two solutions for this, one based on the Contextloaderlistener implementation (this scenario applies only to servlet containers with Servlet2.4 and above specifications). For example, add the following code to Web.:<!--Specify the spring configuration file, with multiple profiles separated by commas--><context-param><param-name> contextconfiglocation</param-name><param-value>classpath:spring-config/applicationcontext.xml</ param-value></context-param><!--Specifies that the spring container be started in listener mode--><listener><listener-class >org.springframework.web.context.ContextLoaderListener</listener-class></listener> Another solution is based on Contextloaderservlet. For example, add the following code to Web.:<!--Specify the spring configuration file, with multiple profiles separated by commas--><context-param><param-name> contextconfiglocation</param-name><param-value>classpath:spring-config/applicationcontext.xml</ param-value></context-param><!--Specifies that the spring container be started in servlet mode--><servlet><servlet-name> context</servlet-name><servlet-class>org.springframework.web.context.contextloaderservlet</ servlet-class><load-on-startup>1</load-on-startup></servlet>  from the order in which the components are loaded when the servlet container starts (servletcontext-> listener->filter servlet), the listener component takes precedence over the servlet component. The servlet-based load scheme is primarily intended to be compatible with Servlet2.3 and the following specifications for servlet containers. With Tomcat as an example, the Tomcat 5.x has already supported the Servlet2.4 specification, so starting the spring container based on listener is now the mainstream choice.

ApplicationContext instantiation of Web projects

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.