@Inject
@Inject ist die generische DI-Annotation aus CDI.
Funktioniert für alle Beans, nicht nur EJBs.
I. Beispiel
public class FooService {
@Inject
private BarHelper helper; // CDI füllt das Feld
}
II. @Inject vs. @EJB
| @Inject | @EJB | |
|---|---|---|
| Aus | CDI | EJB-Spec |
| Für | Alle Beans (POJO + EJB) | Nur EJBs |
| Braucht | beans.xml aktiv | EJB-Container |
Tip
In modernen Apps oft @Inject bevorzugt, weil universeller.