Spring 过滤器DelegatingFilterProxy No WebApplicationContext found: no ContextLoaderListener registered?

本文解答了使用Spring过滤器org.springframework.web.filter.DelegatingFilterProxy时出现的NoWebApplicationContextfound错误,指出问题可能在于未正确注册ContextLoaderListener。提供了解决方案,包括在web.xml中添加相应的监听器和配置applicationContext.xml文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先说明一下,如果使用Spring 过滤器org.springframework.web.filter.DelegatingFilterProxy的时候出现错误“No WebApplicationContext found: no ContextLoaderListener registered?”的解决方案
出现这个问题,应该不是过滤器本身的问题,而是对web.xml相关内容了解的不够,可以参看:
http://www.cnblogs.com/JesseV/archive/2009/11/17/1605015.html

该错误说明ContextLoaderListener 没有注册,需要在web.xml文件中添加org.springframework.web.context.ContextLoaderListener,具体可以参看:http://blog.csdn.net/seng3018/article/details/6758860

添加代码如下:

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

在配置了ContextLoaderListener之后,需要添加applicationContext.xml文件,有两种方式:

第一种:直接将之放到/WEB-INF下,之在web.xml中声明一个listener。(名字必须为:applicationContext.xml)

第二种:将之放到classpath下,但是此时要在web.xml中加入,用它来指明你的applicationContext.xml的位置以供web容器来加载,在web.xml中添加如下内容:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
</context-param>
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值