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