@EJB

@EJB ist die Annotation für Dependency Injection von EJBs.

Der WildFly-Container füllt das Feld automatisch.

I. Beispiel


@EJB
private HelloBean helloBean;   // Container füllt das, kein new!

II. Regeln


Häufigster Newbie-Fehler

@EJB-Feld ist null zur Laufzeit:

  • new benutzt statt Injection
  • beans.xml fehlt oder am falschen Ort
  • javax.* statt jakarta.* importiert