Spring-servlet.xml and Application.xml configuration locations and meanings in Web. XML2015-09-12 18:04 18451 People read comments (0) favorite reports Classification:Web. Xml
(8)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
When we carry out spring-servlet development, often encounter configuration file configuration problem, to solve this problem thoroughly, we need to understand the basic architecture of SPRINGMVC design
The 1.SpringMVC configuration is divided into two parts application.xml and Spring-servlet.xml
2. Function and configuration location of two configuration files
2.1.application.xml: Corresponds to a system-level configuration that is scoped to the system context.
2.2.spring-servlet.xml: corresponding to the controller level configuration, the scope is the control layer context.
3. Their configuration in Web. xml
3.1. Because Application.xml is a system-level context, its initialization needs to be placed in the <context-param> tag in Web. XML, while other configuration files like scheduled tasks are initialized under this tab.
3.2. Since Spring-servlet.xml is only a controller-level context, it is plainly a servlet-level initialization that does not involve any entity other than forwarding, so its scope is limited to the servlet level only. So it should be initialized with spring's dispatcherservlet, so it's initialized in the <servlet> expression. It has a default value of "/web-inf/remoting-servlet.xml", note that the corresponding name of the configuration file is "Servlet-name"-servlet.xml, so if you do not give the servlet the location of the configuration file, And there is no configuration file in the default location, then the system starts with an error.
Note: For what should be initialized in the servlet configuration file, in addition to the resolution of the view, the location of the static resource file, the controller initialization mode, the other should not be placed in the servlet configuration file, it should only be responsible for the forwarding of the request, Parsing of the returned results and parsing of static resource files, initialization of other objects, scheduled tasks ... Should not be placed under this configuration file for management.
[HTML]View PlainCopy
- <? XML version= "1.0" encoding="UTF-8"?>
- <Web-app xmlns="Http://java.sun.com/xml/ns/javaee" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "
- xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee
- Http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "
- version= "3.0" metadata-complete="true">
- <!--This place defaults to the configuration files for system variables, which belong to the system level configuration- -
- <context-param>
- <param-name>contextconfiglocation</param-name>
- <param-value>
- Classpath:spring/application.xml.xml,
- Classpath:spring/spring-quartz.xml
- </param-value>
- </context-param>
- <context-param>
- <param-name>webapprootkey</param-name>
- <param-value>webapp.root</param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.util.webapprootlistener</listener-class >
- </Listener>
- <!-- <context-param>
- <param-name>logbackconfiglocation</param-name>
- <param-value>classpath:conf/logback.xml</param-value>
- </Context-param>-->
- <!-- <listener>
- <listener-class>xorg.springframework.web.util.logbackconfiglistener</ Listener-class>
- </Listener>-->
- <listener>
- <listener-class>com.cloudfarmhdapi.admin.listener.systemlistener</listener-class >
- </Listener>
- <!--This place loads the configuration files for the servlet's variables, which are configured at the controller level
- 1. If you do not configure the configuration file location for this servlet-context.xml,
- Then the default will go to the/web-inf/servlet-context.xml below to find this file
- 2. If this location is configured, it will go to the location to load the file
- -->
- <servlet>
- <servlet-name>appservlet</servlet-name>
- <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class >
- <init-param>
- <param-name>contextconfiglocation</param-name>
- <param-value>classpath:spring/servlet-context.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>appservlet</servlet-name>
- <url-pattern>/</url-pattern>
- </servlet-mapping>
- <!--charactor encoding --
- <filter>
- <filter-name>encodingfilter</filter-name>
- <filter-class>org.springframework.web.filter.characterencodingfilter</ Filter-class>
- <init-param>
- <param-name>encoding</param-name>
- <param-value>utf-8</param-value>
- </init-param>
- </Filter>
- <filter-mapping>
- <filter-name>encodingfilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <!--Shiro Security filter --
- <filter>
- <filter-name>shirosecurityfilter</filter-name>
- <filter-class>org.springframework.web.filter.delegatingfilterproxy</filter-class >
- <init-param>
- <param-name>targetfilterlifecycle</param-name>
- <param-value>true</param-value>
- </init-param>
- </Filter>
- <filter-mapping>
- <filter-name>shirosecurityfilter</filter-name>
- <url-pattern>/*</url-pattern>
- <dispatcher>request</Dispatcher>
- <dispatcher>forward</Dispatcher>
- <dispatcher>error</Dispatcher>
- </filter-mapping>
- <session-config>
- <session-timeout>60</session-timeout>
- </session-config>
- <welcome-file-list>
- <welcome-file>index.htm</welcome-file>
- </welcome-file-list>
- </Web-app>
Spring-servlet.xml and Application.xml configuration locations and meanings in Web. xml