首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

Spring中DispatcherServlet与ContextLoaderListener的差异

2012-07-01 
Spring中DispatcherServlet与ContextLoaderListener的区别昨天在写springmvc的时候,在web.xml中配置了Disp

Spring中DispatcherServlet与ContextLoaderListener的区别

昨天在写springmvc的时候,在web.xml中配置了DispatcherServlet,如下:

<listener>  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  </listener>  <context-param>  <param-name>contextConfigLocation</param-name>  <param-value>/WEB-INF/classes/applicationContext-*.xml</param-value>  </context-param>

?他们都是去加载spring的配置文件,那么他们有什么不同呢?后来在网上查了下资料,发现他们的作用域是不同的,在dispatcherServlet中加载的配置文件的作用域是在web请求的时候才触发的,一般跟controller相关的bean配置会放在这里面,例如视图解析器的bean,而ContextLoaderListener加载的配置文件的作用域是在整个环境中,类似于application级别的,一般在这个配置文件中定义的是公共的内容,例如db、service等等。写的很浅,欢迎拍砖....

热点排行