将ContextLoaderListener添加到Spring MVC中的web.xml [英] Adding ContextLoaderListener to web.xml in Spring MVC

查看:111
本文介绍了将ContextLoaderListener添加到Spring MVC中的web.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Spring MVC 的新手。我有一个Web应用程序。我有以下配置:

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>


推荐答案

是的,你需要添加 ContextLoaderListener web.xml 中,
如果您还要加载其他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>

这篇关于将ContextLoaderListener添加到Spring MVC中的web.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆