Announcement Announcement Module
Collapse
No announcement yet.
Spring Portlet MVC and bean scopes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Portlet MVC and bean scopes

    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

    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 the PetSitesRedirectController I only added getter and setter for favourite property.

    In web.xml i have tried the following things in separatley and in combination:

    1. add a listener:
    Code:
     	<listener>
    		<listener-class>
    			org.springframework.web.context.request.RequestContextListener
    		</listener-class>
    	</listener>
    2. add a filter:
    Code:
    <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>
    3. Filter with diffrent mapping
    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>
    In all above cases I get the following error:
    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.
    What am I missing?

    Best Regards
    Erik Mellegård

  • #2
    Well, I've nearly the same problem with my globalSession in WebSphere Portal. Did anyone find a solution?

    Comment


    • #3
      resloved?

      Have you found the solution for this?

      Comment

      Working...
      X