1
我定义了一个接口。EJB作为接口不被注入
@Local
public interface MessageService {
}
和一个实现。
@Stateless
public class MessageServiceSome implements MessageService {
}
当我试图把它注入到我的资源类,我得到了null
。
//@Path("/messages") // I'M NOT GOING TO MAKE THIS STATELESS!!!
public class MessagesResource {
// none of follwoing options works
// leaves the field null
@Inject
//@EJB
//@EJB(beanName = "MessageServiceSome")
private MessageService messageService;
}
我该如何解决这个问题?
UPDATE
我想我不得不承认,我的问题是不够好。
MessagesResource
类实际上是一个子资源。我不知道区别。
这个问题有两个非常好的线程。
一种是使用ResourceContext和另一种是采用Inject。
这两个线程都说他们工作,但我只成功@Inject
。