being new to CDI, i want to know the practical difference between an alternative and a Qualifier.
in Weld reference, it's stated that:
4.3. Qualifier annotations
If we have more than one bean that implements a particular bean type, the injection point can specify exactly which bean should be injected using a qualifier annotation.
but while explaining the Alternatives, it is said:
4.7. Alternatives
Alternatives are beans whose implementation is specific to a particular client module or deployment scenario.
If I understood right, @Qualifier defines which implementations of the target bean get injected to the Injection Points.
on the other hand @Alternative describes a wish during deployment dependending on the client about whether or not an Alternatice to the standard (the "@default" I mean ) bean get Injected to the injection's point.
It is right ?
Yes, that's right. You can imagine qualifiers as the basic weaving that you setup at development time, using annotations in your source code.
Alternatives allow you to overwrite this at execution time using the beans.xml
file - a simple deployment artifact.
A typical scenario would be to use different beans.xml
for different environments and thereby enable mock-alternatives for components that you don't want to execute on your local / integration environments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With