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"

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!


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.


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.

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

It is surprising that CDI expert committee completely overlooked the necessity to manually register beans or specify beans.xml file from alternative locations, or specify jar-file paths in one beans.xml.

This would have reduced the need for a lot of boiler plate code to make classes outside the established JEE deployment structure available as CDI beans.

I hope at least JEE-8 fixes this shortcoming, and makes manual registration of CDI beans simpler.

Posted by Samba Kolusu on August 06, 2015 at 07:57 PM CEST #

Hi Adam,
ho can i define Alternatives across jars... by default the alternative only works for the beans in current jar. is there any annotation or some option in beans.xml.. (i m new to this thing). thanks

Posted by manoj on July 08, 2016 at 11:55 AM CEST #

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