我使用JSF 2作爲視圖,Spring使用業務邏輯。我想設置一個會話範圍使用註釋我的春天豆一(@Scope(「會議」)),但我得到這個異常:在Spring Beans中使用會話作用域
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'handleFiles': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private creazione.util.FTPOperations creazione.components.HandleOldFiles.operations;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'ftpOperations': 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.
我知道RequestContextListener。它在我的web.xml中。我還添加了RequestContextFilter兩個:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<filter>
<filter-name>requestContextFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>requestContextFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
似乎沒有任何工作。我究竟做錯了什麼? 謝謝!
是啊,但我使用的註解。我有相當多的spring bean在applicationContext.xml中編寫。是否有與 等效的註釋? –
spauny
嘗試看看這個問題http://stackoverflow.com/questions/4503606/annotation-equivalent-of-aopscoped-proxy – stivlo
仍然沒有工作......我已經添加@Scope(value =「session」 ,proxyMode = ScopedProxyMode.INTERFACES),我爲每個spring bean重構了一個接口,但是現在AutoWiring不再識別我的bean了...... – spauny