I have a CDI bean implementation in a dependency jar file:
@ApplicationScoped
public class MyService {
public String doSomething() {...}
}
In my webapp, I want to access that service via EL Expression, therefore I have to give it a @Named
annotation. But I cannot add the annotation on the MyService
implementation because I don't have the rights to change that code.
Therefore I tried creating a producer like
public class MyServiceProducer {
@Inject MyService myService;
@Produces @Named("myService")
public MyService produceNamedInstance() {
return myService;
}
}
This results in a
WELD-001409 - ambiguous dependency for type MyService with qualifiers @Default ... Possible dependencies: - Managed Bean [class ...MyService] with qualifiers [@Any @Default] - Producer Method [myService] with qualifiers [@Default @Named @Any] declared as [...]
How can I add a @Named
annotation without touching the original source code?