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/