1
A completely empty beans.xml
is the same as having a beans.xml
inside the archive with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>
Because of bean-discovery-mode="all" the archive will be scanned for beans. No need to annotate them.
2
A non-existent beans.xml
it is the same as having a beans.xml
inside the archive with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="annotated">
</beans>
Because of bean-discovery-mode="annotated" the archive will be scanned for beans among classes that are annotated (e.g. @Dependent
). All other classes will be ignored, therefore cannot be injected as beans.
3
A third option is to declare bean-discovery-mode="none" in which case the server never scans the archive for beans.
4
Now for the case on which you want to load a class as a bean but you cannot access the archive (e.g. external library) and the class is not annotated, the solution is to use a Producer methods (with or without qualifiers).