web项目启动时,
容器(Tomcat)加载web.xml
加载顺序
<context-param>
由于ContextLoaderListener加载时,会查找名为contextConfigLocation的参数.
因此,配置context-param时参数名字应该是contextConfigLocation.
所以context-param参数的名字是固定的contextConfigLocation.
<listener>
<filter>
<servlet>
1 <context-param> 2 <param-name>contextConfigLocation</param-name> 3 <param-value>classpath:spring-config.xml</param-value> 4 </context-param>
1 <listener> 2 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 3 </listener>
1 <!-- Spring字符集过滤器 --> 2 <filter> 3 <filter-name>characterEncoding</filter-name> 4 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 5 <!-- 设置request所指定字符集 --> 6 <init-param> 7 <param-name>encoding</param-name> 8 <param-value>UTF-8</param-value> 9 </init-param> 10 <!-- 设置response所指定字符集 --> 11 <init-param> 12 <param-name>forceEncoding</param-name> 13 <param-value>true</param-value> 14 </init-param> 15 </filter> 16 <!-- filter过滤规则 --> 17 <filter-mapping> 18 <filter-name>characterEncoding</filter-name> 19 <url-pattern>/*</url-pattern> 20 </filter-mapping>
1 <servlet> 2 <servlet-name>dispactherServlet</servlet-name> 3 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 4 <init-param> 5 <param-name>contextConfigLocation</param-name> 6 <param-value>/WEB-INF/spring-mvc.xml</param-value> 7 </init-param> 8 9 <load-on-startup>1</load-on-startup> 10 </servlet> 11 12 <servlet-mapping> 13 <servlet-name>dispatcherServlet</servlet-name> 14 <url-pattern>/</url-pattern> 15 </servlet-mapping>