I have an EJB that depends on another EJB, so I'm going to use dependency injection to satisfy this dependency. My question is: what is the difference, advantage or disadvantage between @Inject and @EJB.
I have an EJB that depends on another EJB, so I'm going to use dependency injection to satisfy this dependency. My question is: what is the difference, advantage or disadvantage between @Inject and @EJB.
For Java EE 6 or 7, the recommendation is to always try to use @Inject
, @EJB
annotations should be used only when a feature with no counterpart in the @Inject
annotation is required.
The idea is that with JSRs 299 (CDI) and 300 (DI) the annotation @Inject
has become a unified mechanism, available to all layers of the application, replacing previous annotations specific to technologies such as EJB and JSF.
That said, for some cases you end up having to use the root technology annotations.
For the @EJB
annotation there are some typical cases of use like:
beanName
, lookup
and mappedName
to deal with these variations. Fonts :