I want to migrate a Stateful Session Bean (EJB 2.1) to a Spring bean. Both the Stateful Bean and the Spring Bean shall run in Websphere Application Server using the Websphere Transaction Manager (the WebsphereUowTransactionManager
interface allows Spring to access it).
The old Stateful Session Bean implements the SessionSynchronization
interface to make use of the callback methods (specifically the afterCompletion
callback).
I tried using prototype scope for my bean, because to my knowledge this emulates a Stateful bean, and implementing the TransansactionSynchronization interface offered by Spring.
As I later understood, these callbacks can't be called because "In contrast to the other scopes, Spring does not manage the complete lifecycle of a prototype bean: the container instantiates, configures, and otherwise assembles a prototype object, and hands it to the client, with no further record of that prototype instance" http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-factory-scopes-prototype
Session scope could be a solution, but the Session bean is called from a Message Driven Pojo that consumes messages from a JMS Queue.
EDIT: The old session bean is only a "wrapper" for a pure Java class that implements the various writing to queues etc. So it takes the existing class and makes a bean out of it, implementing the SessionSynchronization.
public class XXXMessageSenderBean extends MessageSenderBean implements javax.ejb.SessionBean, SessionSynchronization { }
My idea was to take the same Java class and create a Spring Bean (interface and implementation classes):
public interface XXXMessageSenderPojo extends TransactionSynchronization
public class XXXMessageSenderPojoImpl extends MessageSenderBean implements XXXMessageSenderPojo