the role of the Contextloaderlistener listener is to automatically assemble ApplicationContext configuration information when the Web container is started. because it implements the Servletcontextlistener interface, when the Web. XML configures this listener, when the container is started, it executes the method it implements by default. As for applicationcontext.xml where this configuration file is deployed, how to configure multiple XML files is not explained in detail in the book. The way to do this now is to look at its API documentation. The Contextloader class is associated with Contextloaderlistener, so the entire load configuration process is done by Contextloader. Take a look at its API description.
The first paragraph shows that contextloader can be generated by Contextloaderlistener and Contextloaderservlet. If you look at the Contextloaderservlet API, you can see that it also associates the Contextloader class and it implements the HttpServlet interface.
In the second paragraph, Contextloader creates a class Xmlwebapplicationcontext that implements an interface that is webapplicationcontext-> Configurablewebapplicationcontext->applicationcontext->beanfactory so that all the beans in spring are created by this class
The third paragraph, how to deploy the ApplicationContext XML file.
If you do not write any parameter configuration information in Web. XML, the default path is/web-inf/applicationcontext.xml, and the name of the file created under the Web-inf directory must be applicationcontext.xml;
If you want to customize the file name, you can add contextconfiglocation to the context parameter in Web. XML:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/web-inf/classes/applicationcontext-*.xml
</param-value>
</context-param>
In <param-value> </param-value> Specify the appropriate XML file name, if there are multiple XML files, can be written together and one "," number separated. The applicationcontext-*.xml above uses a wildcard character, For example, in this directory there are applicationcontext-ibatis-base.xml,applicationcontext-action.xml,applicationcontext-ibatis-dao.xml and other files, will be loaded together.
This shows that the Applicationcontext.xml file location can have two default implementations:
The first kind: put it directly under/web-inf, and declare a listener in Web. xml;
The second kind: put it under Classpath, but add <context-param> to the Web. XML, and use it to indicate the location of your applicationcontext.xml to be loaded by the container. According to Struts2, the official files of spring are written as follows:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
</context-param>
Contextloaderlistener function Explanation (turn)