Background:
Developing a spring portlet using Spring Portlet MVC to be used in liferay.
Using Liferay version 5.1.1.
Spring version 2.5.3 in portlet web-inf/lib
To make a clear and reproducible example i restarted with petportal sample portlet from spring.
Problem:
Trying to add session or globalSession scoped beans to petsites-portlet controller (PetSitesRedirectController). In this case (example) I would like to add a favourite petsite bean backed by spring:
from petsites-portlet.xml
In the PetSitesRedirectController I only added getter and setter for favourite property.Code:<bean id="fav" class="org.springframework.samples.petportal.domain.PetSite" scope="session"> <aop:scoped-proxy/> </bean> <bean class="org.springframework.samples.petportal.portlet.PetSitesRedirectController"> <property name="petSites" ref="petSites"/> <property name="favourite" ref="fav"/> </bean>
In web.xml i have tried the following things in separatley and in combination:
1. add a listener:
2. add a filter:Code:<listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener>
3. Filter with diffrent mappingCode:<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> </filter-mapping>
In all above cases I get the following error:Code:<filter> <filter-name>requestContextFilter</filter-name> <filter-class> org.springframework.web.filter.RequestContextFilter </filter-class> </filter> <filter-mapping> <filter-name>requestContextFilter</filter-name> <servlet-name>petsites</servlet-name> <dispatcher>REQUEST</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping>
What am I missing?Code:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.portlet.mvc.annotation.DefaultAnnotati onHandlerMapping#0' defined in PortletContext resource [/WEB-INF/context/petsites-portlet.xml]: Initialization of bean failed; nested exception is org .springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.samples.petportal.portlet.PetSitesRedirectCon troller#0' defined in PortletContext resource [/WEB-INF/context/petsites-portlet.xml]: Error setting property values; nested exception is org.springfr amework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'favourite' threw exception; nested exception is org.springfr amework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.fav': Scope 'session' is not active for the current thread; c onsider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No t hread-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 Dispatc herServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
Best Regards
Erik Mellegård


Reply With Quote
