I have two classes implementing FooInterface: FooAImpl and FooBImpl. FooAImpl has a qualifier (@FooA)
@FooA
public class FooAImpl implements FooInterface{
@Override
public void sayHello() {
System.out.println("A says hello");
}
}
Injecting FooA with qualifier and FooB without qualifier works fine.
public class SomeService {
@Inject @FooA
private FooInterface fooInterface;
public void hello(){
fooInterface.sayHello();
}
}
// call example
weldContainer.instance().select(SomeService.class).get().hello();
But the following does not work.
final FooInterface fooA = weldContainer.instance().select(FooInterface.class,
new FooA.FooALiteral()).get();
org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001308 Unable to resolve any beans for Types: [interface de.laliluna.beans.FooInterface]; Bindings: [@javax.enterprise.inject.Default(), @de.laliluna.beans.FooA()]
at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:809)
The FooALiteral works as I can use the following delegate class to select the FooA implemenation
public static class FooDelegate{
@Inject @Any
private Instance<FooInterface> instances;
public Instance<FooInterface> getInstances() {
return instances;
}
}
// used by
FooDelegate select = weldContainer.instance().select(FooDelegate.class).get();
final FooInterface fooInterface = select.getInstances().select(new FooA.FooALiteral()).get();
What is wrong with my code and is there any direct way to select a qualified instance programmatically?
Best Regards / Viele Grüße
Sebastian