gpt4 book ai didi

java - session 作用域 bean 不是由 DispatcherServlet 创建的

转载 作者:行者123 更新时间:2023-11-30 05:09:13 25 4
gpt4 key购买 nike

我使用 spring 创建了一个 RESTful Web 服务。我有 session 范围内的 Controller 。

当我尝试执行 GET 请求时,它实际上工作得很好,但是当 DispatcherServlet 尝试确定 Last-Modified 值时,我收到一个被忽略的异常。

2010-10-28 11:32:50,487 [http-8080-2] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Spring MVC Dispatcher Servlet' determining Last-Modified value for [/apm/users/1009]

2010-10-28 11:32:50,491 [http-8080-2] DEBUG org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Matching patterns for request [/users/1009] are [/users/{id}]

2010-10-28 11:32:50,491 [http-8080-2] DEBUG org.springframework.web.servlet.DispatcherServlet - Exception thrown in getLastModified org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.userController': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is 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.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:339)

POST 请求也有效,但运行它们时没有出现任何异常。

知道为什么会发生吗?!我能做些什么来防止这种情况发生?!

谢谢!

最佳答案

这是 Spring ( SPR-7456 ) 中的一个错误,已在 Spring 3.0.4 中修复。

作为以前版本的解决方法,您可能可以添加

<listener>org.springframework.web.context.request.RequestContextListener</listener>

到您的web.xml

关于java - session 作用域 bean 不是由 DispatcherServlet 创建的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4041633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com