2011-10-05 60 views
0

我定义与范围请求豆,当我开始我的申请得到一个错误的请求范围豆:如何解决BeanCreateException与Spring MVC框架使用

“无法解析参考豆‘accountDS’,而设置bean属性'accountDS';嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'accountDS'的bean时出错:范围'请求'对当前线程无效;考虑定义该bean的范围代理如果你打算从单例引用;嵌套异常是java.lang.IllegalStateException:找不到线程绑定请求“

我从我的控制器中使用这个bean是一个单身人士。这就是为什么我无法获得请求吗?如果是这样,我如何创建一个范围代理?我的web.xml中也有RequestContextListener,但它没有帮助。

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

你可以发布你的春天背景? – beny23

回答

4
<bean id="..." class="..." scope="request"> 
<aop:scoped-proxy /> 
</bean> 
+0

作品,谢谢! :) – TastyCode

+0

不客气。 – pap

+0

您也可以使用@Scope注释来执行此操作:http://stackoverflow.com/questions/4503606/annotation-equivalent-of-aopscoped-proxy – etherous