The following Web. XML Example:
1. Load Contextconfiglocation with spring configuration
2. Configuring the Spring-mvc Contextconfiglocation
<servlet> <Servlet-name>Spring-mvc</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <Init-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:spring/spring-*.xml</Param-value> </Init-param> <Load-on-startup>1</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Spring-mvc</Servlet-name> <Url-pattern>/</Url-pattern> </servlet-mapping> <Listener> <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener> <Context-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:spring/spring-*.xml</Param-value> </Context-param>
Looked at the configuration, spring the following file was loaded once in SPRINGMVC and loaded again in the context.
You can see it from the Start log and start time. add: Repeated loading also causes the configured Task,schadule task to execute repeatedly!
Therefore, it is reasonable to take the definition of SPRING-MVC as a separate definition when the Web container starts to load, the name is changed to Servlet-mvc.xml to avoid being loaded repeatedly by spring, and in the spring core XML definition, do not appear MVC
<servlet> <Servlet-name>Spring-mvc</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <!--find the XML file configuration for the controller location - <Init-param> <Param-name>Contextconfiglocation</Param-name> <!--find here can be configured multiple, separated by commas or with a wildcard * that is, the second line - <Param-value>/web-inf/classes/servlet-mvc.xml</Param-value> </Init-param> <Load-on-startup>1</Load-on-startup> <async-supported>True</async-supported> </servlet>
SPRINGMVC XML is configured separately, spring itself tube spring, springmvc tube springmvc, so OK
Summary: The separate configuration should not be combined. Note that the code uses
Spring configuration file is loaded two times