<context-param>的contextConfigLocation以及DispatcherServlet的contextConfigLocation
2014-12-10 13:12
351 查看
<pre name="code" class="html"><?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name></display-name> <!-- context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/applicationContext.xml,/WEB-INF/classes/module/*Context.xml </param-value> </context-param --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/servlet-context.xml,/WEB-INF/classes/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- springmvc 请求配置文件 --> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/servlet-context.xml,/WEB-INF/classes/applicationContext.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>-----------------------------------------------------------------------
在web.xml中通过contextConfigLocation配置spring,<span style="font-family: 新宋体;">contextConfigLocation</span>参数定义了要装入的 Spring 配置文件。如果想装入多个配置文件,可以在 <code><param-value></code>标记中用逗号作分隔符。---------------------------------------------------------------在web.xml里配置Listenerxml 代码如下:< listener >< listener-class > org.springframework.web.context.ContextLoaderListener listener-class >< / listener >如果在web.xml里给该Listener指定要加载的xml,如:xml代码如下:<!-- spring config --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param>则会去加载相应的xml,而不会去加载/WEB-INF/下的applicationContext.xml。但是,如果没有指定的话,默认会去/WEB-INF/下加载applicationContext.xml。
相关文章推荐
- <context-param>的作用
- <context-param>与<init-param>的区别与作用
- <context-param>与<init-param>的区别与作用
- <context-param>与<init-param>的区别与作用
- <context-param>与<init-param>的区别与作用
- <context-param>与<init-param>的区别与作用
- <context-param>与<init-param>的区别与作用
- <context:component-scan base-package="">与 <context:annotation-config/>的区别
- Spring配置中的<context:annotation-config/>
- <context-param>与<init-param>的区别与作用
- <context-param>与<init-param>的区别与作用
- <context-param>与<init-param>的区别与作用
- <context-param>与<init-param>的区别
- <context-param>与<init-param>的区别与作用
- <context-param>与<init-param>的区别与作用
- <context:annotation-config/>
- <context-param>与<init-param>的区别与作用
- <context:annotation-config/>
- <context-param>与<init-param>的区别与作用
- <context-param>与<init-param>的区别与作用