读书人

Spring中DispatcherServlet与ContextL

发布时间: 2012-07-01 13:15:00 作者: rapoo

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等等。写的很浅,欢迎拍砖....

读书人网 >开源软件

热点推荐