我是靠谱客的博主 英俊书包,这篇文章主要介绍web.xml中context-param和DispatcherServlet中的contextConfigLocation的区别,现在分享给大家,希望可以做个参考。

web.xml
ContextLoaderListener的配置

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath*:com/**/server/META-INF/spring.xml,/WEB-INF/spring.xml</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

DispatcherServlet的配置

	<servlet>
		<servlet-name>spring-mvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/spring-context.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

两者配置文件的不同之处如下:
在这里插入图片描述
从图中可以看出:

ContextLoaderListener初始化的上下文加载的Bean是对于整个应用程序共享的,不管是使用什么表现层技术,一般如DAO层、Service层Bean;

DispatcherServlet初始化的上下文加载的Bean是只对Spring Web MVC有效的Bean,如Controller、HandlerMapping、HandlerAdapter等等,该初始化上下文应该只加载Web相关组件。

最后

以上就是英俊书包最近收集整理的关于web.xml中context-param和DispatcherServlet中的contextConfigLocation的区别的全部内容,更多相关web.xml中context-param和DispatcherServlet中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(136)

评论列表共有 0 条评论

立即
投稿
返回
顶部