所以我有一个处理用户的ejb。我想从多个其他EJB访问此ejb中的信息。
我不能使用单例,因为这意味着bean将与所有用户共享。每个用户应该只有一个EJB实例。
似乎在我注入ejb的每个地方都会创建一个新实例
简化示例:
@Stateful
@LocalBean
public class Producer implements ProducerLocal {
public User user = null;
// getter/setters omitted
}
@Stateful
@LocalBean
public class Consumer implements ConsumerLocal {
@Inject @SessionScoped
private Producer producer;
// getter/setters omitted
// Another similar consumer sets the user in producer
// Getting the user here raises a null pointer exception
// Because this has a different instance of the producer
}