I have a problem trying to inject a contract with two services bound to it.
I'm using Jersey, and extending ResourceConfig
to configure my app, where I'm binding two different implementations (classes FooImpl1
and FooImpl2
) to a same contract (interface Foo
), ranking them differently. Each of these implementations is annotated with @Named
and its name.
In one of my controllers I want to have access to both implementations, so I inject an IterableProvider<Foo> fooProvider
.
If I do not specify anything, the implementation with the highest rank is injected always, which is what I want.
The problem appears when I want a concrete implementation, one of them. When I call fooProvider.named( nameOfTheClass ).get()
, is returning me null, but if I iterate over the fooProvider, I can have access to both implementations, so they are injected.
Anybody has an idea of what could I be missing?
Thanks a lot for your help.
See Question&Answers more detail:os