简体   繁体   English

如何为与Spring MVC框架一起使用的请求范围Bean修复BeanCreateException

[英]How to fix BeanCreateException for a request scope bean used with Spring MVC framework

I define a bean with scope request and get an error when i start my application: 我用范围请求定义一个bean并在启动应用程序时收到错误消息:

"Cannot resolve reference to bean 'accountDS' while setting bean property 'accountDS'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountDS': Scope 'request' 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" “设置bean属性'accountDS'时无法解析对bean'accountDS'的引用;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'accountDS'的bean时出错: 作用域'request'对于当前线程无效;如果要从单例对象中引用该bean,请考虑为其定义一个作用域代理 ;嵌套的异常是java.lang.IllegalStateException:未找到线程绑定请求”

I am using this bean from within my controller which is a singleton. 我正在从我的控制器(是单例)中使用此bean。 Is this why i can't get a request? 这就是为什么我无法收到请求吗? If so how can i create a scoped proxy? 如果是这样,如何创建作用域代理? I also have RequestContextListener in my web.xml but it doesn't help. 我的web.xml中也有RequestContextListener,但这没有帮助。

    <listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<bean id="..." class="..." scope="request">
<aop:scoped-proxy />
</bean>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM