-
1. Re: Produces method with interface arg. fails when interface has 2 implementations
mkouba Oct 29, 2014 9:47 AM (in response to dde)Hi Dieter,
the example seems to be a bit confused. Where's the definition of the @Jdbc annotation (see MyProducer.create)? Also what's the way you are "asking the container", do you use BeanManager or is there another bean with an injection point? A full stack trace would be also helpful.
-
2. Re: Produces method with interface arg. fails when interface has 2 implementations
dde Oct 29, 2014 10:53 AM (in response to mkouba)I'm sorry, replacing names was not completely done. @Jdbc should've been @Def.
I retrieve the instance with:
WeldContainer container = new org.jboss.weld.environment.se.Weld.Weld().initialize();
container.instance().select(new TypeLiteral<Pro>(){}).get();
This code is used for an integration test.
-
3. Re: Re: Produces method with interface arg. fails when interface has 2 implementations
mkouba Oct 29, 2014 11:17 AM (in response to dde)Ok. First of all, TypeLiteral only makes sense for parameterized types. So
instance.select(Type.class)
would be better.WeldContainer.instance().select(new TypeLiteral<Pro>)
is actually looking for a bean with typePro
and qualifier@Any
(see alsoorg.jboss.weld.environment.se.beans.InstanceManager
). In your exampleOtherPro
is the only matching bean - the producer method MyProducer.create is ignored because it's not "a default-access, public, protected or private, non-abstract method of a managed bean class or session bean class" (note that MyProducer is not a bean because it doesn't have an appropriate constructor, see also http://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#producer_method). If you move the producer method into a separate class (probably a valid bean), there are two beans which satisfy the required type and qualifiers, neither of which is an alternative. And so the container complains about ambiguity.