在 Spring MVC 中将 ContextLoaderListener 添加到 web.xml [英] Adding ContextLoaderListener to web.xml in Spring MVC
本文介绍了在 Spring MVC 中将 ContextLoaderListener 添加到 web.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Spring MVC 的新手.我有一个网络应用程序.我有以下配置:
I am new to Spring MVC. I have a web application. I have the following configuration:
<welcome-file-list>
<welcome-file>list.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
我需要将以下行添加到 web.xml 文件中吗?
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
推荐答案
是的,您需要在 web.xml
中添加 ContextLoaderListener
,只有如果您还想在加载应用程序时加载其他 Spring 上下文 xml 文件你可以将它们指定为
Yes you need to add ContextLoaderListener
in web.xml
,
only if you want to load other Spring context xml files as well while loading the app
and you can specify them as
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-security.xml
</param-value>
</context-param>
这篇关于在 Spring MVC 中将 ContextLoaderListener 添加到 web.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文