Announcement Announcement Module
Collapse
No announcement yet.
Access Stateful Beans from a remoting destination Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Access Stateful Beans from a remoting destination

    hi, i'm using Spring flex integration in Jboss 4.3 AS. My application expose a bean as a remoting-destination. this bean look-up a stateful bean with a <jee-jndi-lookup> element:
    Code:
    	<bean id="statisticsProvider" class="org.my.flex.services.StatisticXmlProvider">
    		<property name="statisticsService" ref="statistics" />
    		<flex:remoting-destination/>		
    	</bean>
    
    	<jee:jndi-lookup id="statistics" jndi-name="ejb/StatisticsService"  />
    with this configuration my flex app respond that server throw a nullpointer 'cause cannot find the stateful bean. The refs are correctly listed inside both web.xml and jboss-web.xml descriptors.

    I've tryed to add scope="session" and lazy-init="true" to statisticsProvider bean, but during the webapp startup spring tells me:

    Code:
    17:13:04,119 ERROR [DispatcherServlet] Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.flex.remoting.RemotingDestinationExporter#0': Cannot resolve reference to bean 'statisticsProvider' while setting bean property 'service'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'statisticsProvider': 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.
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:315)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1243)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1011)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:475)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:412)
    	at java.security.AccessController.doPrivileged(Native Method)

    i'm using DispatcherServlet integration, and I've guessed that all calls to bean would be launched from an http request. Also including RequestContextLIstener in web.xml do not solve the problem.

    is there a "correct way" to do what I want?

    thank for any support

  • #2
    Well, first off you probably need to configure the JNDI lookup a little differently so that it happens lazily if the object being looked up is scoped to the session. You'll probably also want to disable caching of the object reference.

    Take a look at JndiObjectFactoryBean to understand what exactly the <jee:jndi-lookup> tag is configuring:
    http://static.springsource.org/sprin...ctoryBean.html

    Secondly, to properly make statisticsProvider session scoped, you need to use a scoped-proxy as described in the Spring reference manual so that when BlazeDS invokes methods on it, the proper instance is retrieved:
    Code:
    <bean id="statisticsProvider" class="org.my.flex.services.StatisticXmlProvider" scope="session">
    	<property name="statisticsService" ref="statistics" />
            <aop:scoped-proxy />
    	<flex:remoting-destination/>		
    </bean>

    Comment


    • #3
      Thanks for your response, the problem of looking up the stateful bean is solved, but another one is rised on! This is how I've configured my jndi-look-up:

      Code:
      <jee:jndi-lookup id="statistics" jndi-name="ejb/StatisticsService"    cache="false" 
      lookup-on-startup="false" 
      proxy-interface="org.my.business.StatisticsService"  />
      every call on my <mx:remoteObject>, from the flex font-end, is now creating a new instance of the statefulbean, instead of using a session scoped one!

      I'm using a flex session defined in web.xml:

      Code:
      <listener>
          	<listener-class>flex.messaging.HttpFlexSession</listener-class>
        </listener>
      I don't know if this is the right place to post about this problem, maybe it can be related to aop o spring-web configurations ...
      Or my problem can be the bean exposed as remoting-destination instead of the Stateful ejb?

      Stefano

      Comment

      Working...
      X