Adam Bien's Weblog

Wednesday Jul 10, 2013

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!


NEW workshop: Microservices with Java EE 7 and Java 8, January 26th, 2015, Airport Munich

A book about rethinking Java EE Patterns

Comments:

If the cure is more XML, does it cross anybody's mind that the disease is XML?

Posted by Tim Boudreau on July 11, 2013 at 02:24 PM CEST #

Can you help me fix the issue ?

I am using GF4 and created a class in application client jar and trying to inject it into EJB module and Web mobule. but i am getting below exception.

org.jboss.weld.exceptions.DeploymentException:

Posted by krishna kodali on August 04, 2013 at 07:01 AM CEST #

Hi Adam
Is it possible to @Inject String (having @Produces method defined elsewhere) while bean-discovery-mode is set to annotated???? Of course JavaEE7 and GF4.0.
Thanks.
Bartek

Posted by Bartek on August 05, 2013 at 05:30 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License