9
I have an EJB that relies on another EJB, so I’m going to use dependency injection to satisfy that dependency. My question is: what is the difference, advantage or disadvantage between @Inject and @EJB.
9
I have an EJB that relies on another EJB, so I’m going to use dependency injection to satisfy that dependency. My question is: what is the difference, advantage or disadvantage between @Inject and @EJB.
9
For Java EE 6 or 7, the recommendation is to always try to use @Inject
, annotations @EJB
should be used only when a feature without counterpart in the annotation @Inject
is necessary.
The idea is that with Jsrs 299 (CDI) and 300 (DI) the annotation @Inject
became a unified mechanism, available for all application layers, replacing previous annotations specific to technologies such as EJB and JSF.
That said, for some cases you end up having to use the annotations of the root technology.
For the annotation @EJB
there are some typical cases of use as:
beanName
, lookup
and mappedName
to deal with these variations.Sources:
+1, Just to complement: comparing on an application server, there is not much difference compared to performance that justifies that CDI Beans are "lighter" than Ejbs.
Browser other questions tagged java ejb dependency-injection
You are not signed in. Login or sign up in order to post.
Very good @Wakim. Do you think it would be cool to see the differences and put here to the Brazilian public?
– Jonathan Camilo Lima
Is this question about a specific programming language? If so, add the language tag.
– user7261