Results 1 to 7 of 7

Thread: Accessing a STATEFUL Session Bean

  1. #1
    Join Date
    May 2005
    Location
    Columbus, OH
    Posts
    12

    Default Accessing a STATEFUL Session Bean

    Hello everyone,

    I have been searching for examples on how to configure Spring to return the Remote interface for a STATEFUL Session Bean and have been unsuccessful. Its easy to do with a Stateless Session bean using the <jee:remote-slsb/> tag. Is there something similar to help with Stateful beans?

    Any examples would be excellent.

  2. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Afaik SFSB support is not provided to the same extend as SLSB support. Mostly because of the initialization and remove issues it entails.

    But you can have a look at the Jira issue I referred to in another post.

    I provided implementation classes there which include a SimpleRemoteStatefulSessionProxyFactoryBean. It is to be used the same as its stateless counterpart. The only difference is, that prior to using the returned bean and after finished using it the appropriate SfsbHelper-methods have to be invoked (class also contained in the sources).

    Hope that helps,
    Andreas

  3. #3
    Join Date
    Dec 2005
    Location
    U-241
    Posts
    237

    Default

    That's what I'm doing with JBoss 4.x...
    Code:
    <bean
            id="parentEJB"
            abstract="true"
            lazy-init="true"
            class="&JndiObjectFactoryBean;">
            <property
                name="jndiEnvironment"
                ref="securedEnvironment" />
        </bean>
        <bean
            name="initSFSB"
            parent="parentEJB"
            scope="prototype">
            <property
                name="jndiName"
                value="${jndi.ejb.init}" />
        </bean>
    jndi.ejb.init=jspring/InitBean/remote

    Works like a charm.

    Cheers.
    Spring, it's a wonderful thing...

  4. #4
    Join Date
    Jul 2007
    Posts
    5

    Default Documentation/Example

    For Andreas - I have downloaded the zip file from the jira forum you mentioned. Is there anywhere that I can find further documentation on this. An example of using the SimpleRemoteStatefulSessionProxyFactoryBean would be very helpful.

    -- Bruce

  5. #5
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Hello Bruce,

    first, a general example of the concept is decribed in this post (maybe you already saw it, as I also posted a link to the thread to Jira).

    At the moment I have no example for SFSB at hand, but it is easily explained.

    The configuration of the SimpleRemoteStatefulSessionProxyFactoryBean is exactly as its stateless counterpart. The difference is in its usage. While you can use a stateless proxy directly after injection and do not care about it, you need to initialize the stateful proxy first and have to deinitialize it afterwards. This corresponds to the parameterized invocation of create() before and the required invocation of remove() after using an SFSB.

    If you, for example have a FooService (which is your business interface of the SFSB) your code might look like that:

    Code:
      public class Client {
          // gets injected via Spring as SimpleRemoteStatefulSessionProxyFactoryBean
          private FooService;
    
          // ...
    
          public void doSomething() {
    
              // assuming that the SFSB's create method takes a String and an int/Integer parameter
              SfsbHelper.initSfsbInstance(this.fooService, new Object[] {"Hello", new Integer(42)};
    
              // invoke some method on the now initialized service
              String result = this.fooService.bar(new Date());
    
              // the service might be used further
    
              // Not required to initialize/remove inside the same method but remove has to be called
              SfsbHelper.removeSfsbInstance(this.fooService);
    
              // fooService is still a valid proxy here, but to invoke methods on it,
              // it has to be initialized again as shown above
          }
    }
    I hope that makes it a bit clearer. If not, just follow up on this post.
    And if you find this approach useful, feel free to vote for it on Jira

    Regards,
    Andreas

  6. #6
    Join Date
    Jul 2007
    Posts
    5

    Default Help with deployment problem -- and thanks

    Andreas, Thanks for the reply. I was unclear as to whether you could have the proxy injected into your class or had to do somehting else to get it, your post cleared that up. I have one other thing you could help me with. I took the source files you provided, compiled them and put them in a spring-extensions.jar file, which I included in my EAR file. I then configured my webApplicatoinContext.xml the same as for a statless sesson bean, but change the class to the stateful proxy. Everything went fine until I tried to access the bean (I have lazy-init = true), then I get the ClassNotFoundException listed below. Is there something else I should be doing?

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '/statefulService1' defined in ServletContext resource [/WEB-INF/webapplicationcontext.xml]: Cannot resolve reference to bean 'statefulServiceController' while setting bean property 'serviceController'; nested exception is org.springframework.beans.factory.CannotLoadBeanCl assException: Cannot find class [org.springframework.ejb.access.SimpleRemoteStatefu lSessionProxyFactoryBean] for bean with name 'statefulServiceController' defined in ServletContext resource [/WEB-INF/webapplicationcontext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.ejb.access.SimpleRemoteStatefu lSessionProxyFactoryBean

    - Bruce

  7. #7
    Join Date
    Jul 2007
    Posts
    5

    Default

    I got past this error so don't bother to reply. -- Bruce

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •