在Grails 2.0下的过滤器中找不到“没有找到线程绑定的请求”

时间:2012-01-15 09:36:18

标签: spring grails grails-2.0

我正在开发一个Grails插件,它有过滤器,代码如下:

void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, javax.servlet.FilterChain chain) {

    HttpServletRequest request = servletRequest
    HttpServletResponse response = servletResponse
    String url = request.requestURI.substring(request.contextPath.length())
    logger.debug("Processing url: $url")
    chain.doFilter(servletRequest, servletResponse)
}

非常标准的Java EE过滤器,它扩展了spring GenericFilterBean。它由SpringSecurityUtils.registerFilter %NAME%, %POS%注册(它是春季安全扩展)

升级到Grails 2.0后,我开始在chain.doFilter()行上发现一些奇怪的错误:

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.

请注意String url = request.requestURI.....行的一切正常。显示的网址有效。

这个错误不可预测的问题:(有时过滤器工作正常,有时抛出异常,我无法弄清楚是什么问题,以及我必须做些什么来修复它。可能它取决于bean初始化的顺序,但我不确定


更新:发现这是因为resources插件。删除此插件后错误消失了。不确定这是最好的方式。

1 个答案:

答案 0 :(得分:1)

在Grails 2.0中,默认情况下,webxml插件安装在新项目中。它控制web.xml中过滤器的顺序。 http://grails.org/plugin/webxml