Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 445
Sasikumar Murugesan Avatar asked Nov 01 '22 20:11

Sasikumar Murugesan


1 Answers

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

like image 128
Arunas Junevicius Avatar answered Nov 08 '22 14:11

Arunas Junevicius