0

我目前正在从事一个灰熊、春季和球衣项目,我遇到过:

Caused by: java.lang.IllegalStateException: 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.
    at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
    at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:40)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:328)
    ... 32 more

基于堆栈跟踪(以及我谷歌时的结果),我应该在 web.xml 中注册一个侦听器

<web-app ...>
   <listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
   </listener>
</web-app>

所以我的问题是,如果我没有 web.xml,我将如何将侦听器注册到 grizzly 服务器?

4

1 回答 1

0

在没有看到更多代码的情况下,我的猜测是使用 ServletHandler - 查看该类的 Javadocs 顶部的示例源:

一个普通的 spring 应用程序会为上下文启动注册一个侦听器,然后为大多数其他事情注册调度 servlet,因此您应该能够修改示例代码来执行此操作。

类似的东西(完全未经测试):

sa.setServlet(new org.springframework.web.servlet.DispatcherServlet());
sa.addListener(org.springframework.web.context.ContextLoaderListener.class.getName());
sa.addContextParameter("contextConfigLocation", "beans.xml");
sa.setServletPath("/*");
于 2012-03-28T02:01:26.200 回答