使用session = scope在zk中创建spring bean时出错

时间:2013-11-13 09:59:55

标签: spring mvvm spring-security inversion-of-control zk

在我有

的应用程序上下文中
    <beans:bean id="Facade"
      class="com.facade.Facade"/> 

一切正常,我可以使用SpringUtil.getBean("Facade")

访问外观

但如果我添加session = scope

<beans:bean id="Facade"
      class="com.facade.Facade" scope="session"/>

我得到以下错误....如何解决? 我正在使用zk + spring security

     [java] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'F
acade': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you inte
nd 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? If you are actually operating within a web req
uest and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In thi
s case, use RequestContextListener or RequestContextFilter to expose the current request.

1 个答案:

答案 0 :(得分:0)

您的评论对于解决方案确实是正确的。 但是为什么你想要一个外观进入会话范围呢?

换句话说,您将为您拥有的每个会话一次又一次地创建此bean。 因此,如果5个用户登录,则您有5个相同类的bean。
那仍然是想要的情况吗?

Greetz chill。