先说明一下,如果使用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>