I am not experienced in EJB
and CDI
and I am trying currently to apprehend some basic principles of them and how to use it. In particular I want to grasp the purpose and use of Qualifiers
and I have read the guide. I cannot understand however completely, how a Qualifier
serves as an extention of an interface. Taking as staring point the example in the guide and the statement: "a qualifier is like an extension of the interface. It does not create a direct dependency to any particular implementation. There may be multiple alternative implementations of @Asynchronous PaymentProcessor!", I assume that one can do:
@Asynchronous
public class AsynchronousPaymentProcessor implements PaymentProcessor {
public void process(Payment payment) { ... }
}
and
@Asynchronous
public class OtherAsynchronousPaymentProcessor implements PaymentProcessor {
public void process(Payment payment) { ... }
}
and then they try to inject as:
@Inject @Asynchronous PaymentProcessor asyncPaymentProcessor;
How is it in this case determined, which bean is injected, since both are annotated with the same Qualifier
? Or do the multiple implementations of a qualifier concern only Alternatives
?
Update-Complete:
I have read the relevant questions as well. What I want is an answer without quite a long description: Since I can inject the type class which implements an interface, what is the benefit of injecting the interface type, other that achieving loose coupling? If I try the above code with 2 @Asynchronous
implementations and I receive an Exception, then I infer that it (multiple implementations) is attainable only with alternatives. Am I right?