问题
Is it legal to inject a @Stateful into an MDB?
@Stateful
public class InteruptBean implements Interrupt {
....
}
@MessageDriven(...)
public class EchoTrigger implements MessageListener {
@EJB Interrupt interrupt;
....
}
Or better phrased: Can I use a stateful EJB to pass state around in an asynchronous Event Driven Architecture?
回答1:
Yes, it's "legal", but it's nonsensical. MDBs instances are pooled like SLSBs. The MDB will become non-functional after the SFSB times out.
It might work to explicitly create the SFSB at some point, and then pass a reference to the SFSB in the messages being sent to drive the MDB.
回答2:
Yes it does not make sense. Because stateful session beans are meant for processing multiple requests from same client so that they have client-actions oriented processing. In this case MDB will be beans clients. MDB supports single request model. A request comes to MDB (in form of message) and it is processed. So both types of beans don't match in processing model.
来源:https://stackoverflow.com/questions/6527552/is-it-legal-to-inject-a-stateful-into-an-mdb