This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Accessing a STATEFUL Session Bean

Mar 29th, 2007, 03:26 PM

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?

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

Comment

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.

Comment

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

Comment

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?