This article uses spring3.1.0, which mainly explains spring's configuration file default location and the location of the specified spring configuration file.
1. Default location
A) Default MVC configuration file
Configure in the Web. xml file:
<!--Front Controller--
<servlet>
<servlet-name>annomvc</servlet-name>
< Servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>annomvc</servlet-name>
<url-pattern>/< /url-pattern>
</servlet-mapping>
Specify spring to handle the requested Servlet, by default the address of the MVC configuration file is:/web-inf/${servletname}-servlet.xml, the MVC profile found by default in the example we configured is:/web-inf/ Annomvc-servlet.xml.
B) Other configuration files
The other configuration files here refer to the configuration of the DataSource, the configuration of the persistence layer, the configuration information of the service layer, etc. To load additional configuration files, you need to include a Contextloaderlistener listener in the Web. XML configuration file to configure. The Contextloaderlistener only listens for beans outside the initial chemical control MVC-related configuration. The code is as follows:
<!--context Load listener--
<listener>
<listener-class> Org.springframework.web.context.contextloaderlistener</listener-class>
</listener>
If no other parameters are specified, the default lookup profile location is:/web-inf/applicationcontext.xml.
2) Specify the configuration file location
A) Modify the MVC configuration file location
To modify the location of the MVC configuration file, you need to specify the location of the MVC configuration file when configuring Dispatcherservlet. For example, if you want to put Annomvc-servlet.xml in src/config/annomvc-servlet.xml, you need to specify the <init-param> tag when configuring Dispatcherservlet. The specific code is as follows:
<!--Front Controller--
<servlet>
<servlet-name>annomvc</servlet-name>
< Servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>
<init-param >
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/ annomvc-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping >
<servlet-name>annomvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
B) Modify other configuration file Locations
To modify the configuration file location of a bean other than the MVC configuration file, you need to include the <context-param> tag in Web. XML and specify a specific location. We have three configuration files (Service-context.xml, Persistence-context.xml, datasource-context.xml) They are all located under the src/config/folder, then the configuration code is as follows:
<!--context Load listener--
<listener>
<listener-class> org.springframework.web.context.contextloaderlistener</listener-class>
</listener>
< context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
Classpath:config/service-context.xml
classpath:config/persistence-context.xml
classpath:config/ Datasource-context.xml
</param-value>
</context-param>
OK, in this position you can place your configuration files as you like.