简体   繁体   中英

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 . To use these EJB's in the other EJB's I am currently using the @EJB annotation. 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 . 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 . Or do I get an EJB from the CDI container?

I also guess that by using @Inject I don't get all the EJB features that I would have gotten from @EJB ?

@Inject supports the injection of EJBs. There is no functional difference, CDI is doing a lookup to find the object using the standard JNDI locations. The @EJB annotation has some additional capabilities, mostly around remoting or non standard JNDI locations that wouldn't be supported OOTB by @Inject

关于以下内容的有趣链接: http : //www.oracle.com/technetwork/articles/java/cdi-javaee-bien-225152.html我没有自己尝试过,但看起来@Inject比@EJB更强大...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM