what is difference between @EJB and @Resource? in dependency injection in EJB

余生长醉 提交于 2019-12-23 14:54:00

问题


I like to know what is the main difference between EJB @EJB and @Resource annotation? In which case we have to go for @EJB and @resource


回答1:


Specification states, regarding @EJB:

The Bean Provider uses the EJB annotation to annotate a field or setter property method of the bean class as a target for the injection of an EJB reference. The reference may be to a session bean’s business interface or to the local home interface or remote home interface of a session bean or entity bean.

regarding @Resource(section 16.2.2):

A field or method of a bean class may be annotated to request that an entry from the bean’s environment be injected. Any of the types of resources or other environment entries described in this chapter may be injected.

Mentioned entries include: EJB reference, web service reference, resource manager connection factory reference, message destination reference, unit reference, persistence context reference, UserTransaction, CORBA ORB object, TimerService, EJBContext object



来源:https://stackoverflow.com/questions/24900908/what-is-difference-between-ejb-and-resource-in-dependency-injection-in-ejb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!