在 Spring 框架下使用 filter 引起的一个错误
在 web.xml 配置文件中有如下代码:
<filter>
<filter-name>LoginRequireFilter</filter-name>
<filter-class>com.liumapp.DNSBee.filter.LoginRequireFilter</filter-class>
<init-param>
<param-name>noCheckPath</param-name>
<param-value>login;register;nav</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>LoginRequireFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
很简单的登录过滤器,但是在运行时报出
HTTP Status 500 - No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
的错误。
解决办法:
在上面的 filter 之前加入一段:
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于