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 hasArrayList.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
- With:
- Identifier: MyProject\build\classes\java\main
- Type: All
- Beans.xml: Version not defined.
- With:
- Identifier: org.jboss.weld.environment.deployment.WeldDeployment.additionalClasses
- Type: Annotated
- Beans.xml: No beans.xml
- With:
- 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
- This bean has:
- The result of the
SomeBean
instantiation is located in Archive 2.- This bean has:
- Kind: SYNTHETIC
- Class: j.u.ArrayList
- Qualifiers:
@CustomQualifier
- Scope:
@ApplicationScoped
- This bean has:
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?
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.