beans.xml

beans.xml aktiviert CDI (Contexts and Dependency Injection) in einer App.

Ohne sie → @Inject / @EJB sind null zur Laufzeit.

I. Wo liegt sie?


Verpackung Pfad
WAR WEB-INF/beans.xml
EJB-Jar META-INF/beans.xml

II. Minimaler Inhalt


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
       bean-discovery-mode="all"
       version="4.0">
</beans>

III. bean-discovery-mode


Modus Bedeutung
all Alle Klassen sind CDI-Beans
annotated Nur Klassen mit Scope-Annotation
none CDI deaktiviert
Warning

Falscher Ort = @EJB / @Inject ist null. Häufigster Newbie-Fehler!