What are the best debugging tricks with Weld/CDI?

Short answer: there is no dedicated debug option for CDI (as no such thing is required by the spec), and no dedicated debug option for Weld.

Long Answer: There is a lot you can do on your own. Familiarise yourself with the extension mechanism of CDI, and you’ll discover that you can easily (really!) write your own extension that debugs your required information

What classpath entries are scanned and
where? What was the result?

Listen to the ProcessAnnotatedType-Event

What beans are available for injection
for which class?

Query the BeanManager for that.

What caused a given bean not to be
considered for later? A given jar?

Listen to the AfterBeanDiscovery-Event and see what you’ve got in the BeanManager. Basically, the following scenarios make a ManageBean ineligible for injection:

  • it’s no ManagedBean (like there is no beans.xml in the jar)
  • it does not qualify as a managed bean (https://docs.jboss.org/weld/reference/1.1.0.Final/en-US/html/beanscdi.html#d0e794)
  • it has no BeanType (@Type{})
  • it is vetoed (Seam Solder) or suppressed by any other extension-mechanism

Leave a Comment