Synthetic bean not detected in bean archive due to being added to WeldDeployment.additionalClasses archive

382 views Asked by At

I've been playing with Weld and CDI for a few months now and I've recently come across the following issue.

Problem situation

  • Using Weld SE 3.1.5.Final
  • Created a CDI Extension which adds a bean (SomeBean) using @Observes AfterBeanDiscovery abd
  • SomeBean is a custom bean that has ArrayList.class as Class and returns 1 qualifier (@CustomQualifier).
  • A different bean (DifferentBean) then declares a @Inject @CustomQualifier ArrayList<String> variableName;
  • This injection point fails due to Unsatisfied dependencies.

Investigation

From the Bean Validation Report I've been able to determine that:

  • Weld creates 2 Bean Archives
    1. With:
      • Identifier: MyProject\build\classes\java\main
      • Type: All
      • Beans.xml: Version not defined.
    2. With:
      • Identifier: org.jboss.weld.environment.deployment.WeldDeployment.additionalClasses
      • Type: Annotated
      • Beans.xml: No beans.xml
  • The CDI Extension is a bean located in Archive 1.
  • The result of the DifferentBean instantiation is located in Archive 1.
    • This bean has:
      • Kind: MANAGED
      • Class: my.package.DifferentBean
      • Qualifiers: @Default
      • Scope: @Dependent
  • The result of the SomeBean instantiation is located in Archive 2.
    • This bean has:
      • Kind: SYNTHETIC
      • Class: j.u.ArrayList
      • Qualifiers: @CustomQualifier
      • Scope: @ApplicationScoped

Cause

Based on this I'm presuming that for some reason the SomeBean my custom Extension is adding is being added to archive 2 and therefore not accessible from archive 1 where DifferentBean is located.

If that assessment is correct, how do I resolve this?

1

There are 1 answers

0
Byebye On

I tracked down the issue. I was expecting Weld to resolve the generic for the ArrayList.class to ArrayList. This did not occur, after removing the generic my problem was resolved.