掲示板

Spring's request scope (web-scoped) beans in Liferay portlet

thumbnail
13年前 に Jakub Liska によって更新されました。

Spring's request scope (web-scoped) beans in Liferay portlet

Regular Member 投稿: 187 参加年月日: 10/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
<listener>
		<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
	     </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.
thumbnail
12年前 に Máté Thurzó によって更新されました。

RE: Spring's request scope (web-scoped) beans in Liferay portlet

New Member 投稿: 6 参加年月日: 11/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:


<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>


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