概要:
Spring配置文件是集成了Spring框架的项目的核心,引擎的开始是:容器先是加载web.xml,接着是applicationContext.xml在web.xml里的注册。以下我们将介绍applicationContext.xml在web.xml里的注册的两种方式。
目录
- 添加ContextLoaderListener这个监听器
- 添加ContextLoaderServlet这个servlet
添加ContextLoaderListener这个监听器
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:edu/fjnu/hotelsys/config/*.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>
添加ContextLoaderServlet这个servlet
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <servlet> <servlet-name>context</servlet-name> <servlet-class> org.springframework.web.context.ContextLoaderServlet </servlet-class> </servlet>
注:
ContextLoaderServlet和ContextLoaderListener都是先创建ContextLoader的一个对象,然后调用它的initWebApplicationContex方法初始化WebApplicationContext获得一个对象。
文章出自:http://www.cnblogs.com/mabaishui/archive/2010/07/14/1777233.html