adam bien's blog

When Your DI Breaks: bean-discovery-mode in CDI 1.1 (JavaEE 7) 📎

CDI 1.1 JSR-346 comes with finer scanning control and an attribute bean-discovery-mode with possible values: all, annotated and none:


<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>

However, the suggested value "annotated" only recognizes annotated CDI managed beans. Beans without any annotation are ignored. The value all behaves like in Java EE 6: also beans without any annotations are recognized.

So if DI doesn't work (e.g. org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type…), double check the beans.xml.

See you at Java EE Workshops at MUC Airport!