[英]Injecting EJB with @EJB or @Inject in the service layer for my REST web service?
I have created some EJB's, they are annotated with @Stateless
. 我创建了一些EJB,并用
@Stateless
进行了注释。 To use these EJB's in the other EJB's I am currently using the @EJB
annotation. 为了在其他EJB中使用这些EJB,我目前正在使用
@EJB
注释。 I have created another layer (over the service layer) for my REST web service (I am using JAX-RS) and I wonder if I should use @EJB
or @Inject
. 我为我的REST Web服务创建了另一层(在服务层之上)(我正在使用JAX-RS),我想知道应该使用
@EJB
还是@Inject
。 I know these two are different things - and they probably live in different containers? 我知道这两件事是不同的-它们可能生活在不同的容器中吗? If I use
@Inject
do I get the same EJB that I would have gotten with @EJB
. 如果使用
@Inject
,我将得到与@EJB
相同的EJB。 Or do I get an EJB from the CDI container? 还是从CDI容器中获取EJB?
I also guess that by using @Inject
I don't get all the EJB features that I would have gotten from @EJB
? 我还猜想,使用
@Inject
并不能获得@EJB
提供的所有EJB功能?
@Inject
supports the injection of EJBs. @Inject
支持EJB的注入。 There is no functional difference, CDI is doing a lookup to find the object using the standard JNDI locations. 没有功能上的差异,CDI正在使用标准JNDI位置进行查找以找到对象。 The
@EJB
annotation has some additional capabilities, mostly around remoting or non standard JNDI locations that wouldn't be supported OOTB by @Inject
@EJB
批注具有一些附加功能,主要围绕@Inject
OOTB不支持的远程处理或非标准JNDI位置
关于以下内容的有趣链接: http : //www.oracle.com/technetwork/articles/java/cdi-javaee-bien-225152.html我没有自己尝试过,但看起来@Inject比@EJB更强大...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.