I'm having trouble injecting a delegate. I have a producer field:
private UpperBoundTypedResource<HierarchyHolder<Primate>> ubhhr = new UpperBoundTypedResource<HierarchyHolder<Primate>>(Primate.class);
where @ResourceBinding is a qualifier, and a decorator:
public abstract class UpperBoundDecorator<T extends HierarchyHolder<? extends Primate>> implements UpperBoundTypedResourceIntf<T>
private UpperBoundTypedResourceIntf<T> resource;
public UpperBoundDecorator(@Delegate @ResourceBinding UpperBoundTypedResourceIntf<T> resource)
this.resource = resource;
System.out.println("UpperBoundDecorator got delegate: " + resource);
public Response execute()
Response response = resource.execute();
and the UpperBoundDecorator constructor and UpperBoundDecorator.execute() aren't getting called. UpperBoundTypedResource.execute() gets called directly. There are no complaints from Weld, just a silent failure.
If I remove @ResourceBinding from the UpperBoundDecorator constructor, everything works. If I remove @ResourceBinding from the producer field, Weld complains about an unsatisfied dependency:
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [UpperBoundTypedResourceIntf<T>] with qualifiers [@ResourceBinding] at injection point [[parameter 1] of [constructor] @Inject public org.jboss.resteasy.cdi.generic.UpperBoundDecorator(UpperBoundTypedResourceIntf<T>)]
Running my test in the Eclipse debugger, I see that the instance of UpperBoundTypedResource produced by the producer field doesn't have the qualifier @ResourceBinding, which would explain why it isn't being injected into the UpperBoundDecorator delegate field. But, in that case, I would expect a complaint about an unsatisfied dependency.
Looking at the CDI spec, it doesn't really say much about qualifiers on producer fields and methods. It says, "A producer field may also specify scope, bean name, stereotypes and/or qualifiers.", but it doesn't, as far as I can see, elaborate on the meaning of qualifiers on producer fields. I'm guessing that the intent is to determine if the produced object is eligible for injection into an injection point, but it doesn't seem to be spelled out.
As an experiment, I tried annotating UpperBoundTypedResource with @ResourceBinding, which messes up the injection points in UpperBoundTypedResource, but it does, of course, add the qualifier to the class. When I do that, AbstractClassBean.initDecorators() does, in fact, determine that UpperBoundDecorator is a decorator for UpperBoundTypedResource, but ManagedBean.produce(), which seems to be where decorators are applied, doesn't get called for UpperBoundTypedResource. Note, by the way, that in these circumstances, the instance of UpperBoundTypedResource that eventually gets called by Resteasy is an instance of UpperBoundTypedResource.class, rather than a Weld proxy.