フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Jakub Liska
Spring's request scope (web-scoped) beans in Liferay portlet
2011/04/01 4:02
答え

Jakub Liska

ランク: Regular Member

投稿: 187

参加年月日: 2010/03/25

最近の投稿

Hey,

I have the same issue as this one

It doesn't work for me... I also tried org.springframework.web.filter.RequestContextFilter

And in current LR version 6.1x, if you add
1<listener>
2        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
3         </listener>


into your portlet web.xml, it is preserved in the web.xml after deploy and RequestContextListener is at the first position, right after filters. But I get the same result :

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileProcessingService': 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: 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)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:844)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
... 70 more
Caused by: 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.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:40)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325)
... 75 more



Have anybody experience with this ? Figuring this out is very time consuming.
Máté Thurzó
RE: Spring's request scope (web-scoped) beans in Liferay portlet
2011/08/02 5:14
答え

Máté Thurzó

LIFERAY STAFF

ランク: New Member

投稿: 5

参加年月日: 2011/01/28

最近の投稿

Hi,

It seems the spring beans are being bound to the wrong context. A web.xml setup similar to this might solve your problem:

 1
 2<filter>
 3        <filter-name>requestContextFilter</filter-name>
 4        <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
 5</filter>
 6
 7<filter-mapping>
 8        <filter-name>requestContextFilter</filter-name>
 9        <url-pattern>/*</url-pattern>
10        <dispatcher>REQUEST</dispatcher>
11        <dispatcher>INCLUDE</dispatcher>
12        <dispatcher>FORWARD</dispatcher>
13</filter-mapping>


This will bind the beans into the root context what should work with Liferay.