CDI: @alternative vs @Qualifiers

is new to CDI, I want to know the practical difference between the alternative and the Classifier.

In Link to Weld , she stated that:

4.3. Classifier Annotations

If we have more than one bean that implements a particular type of bean, the injection point can indicate exactly which bean should be entered using the classifier annotation.

but, explaining the Alternatives, it says:

4.7 Alternatives

Alternatives to beans, the implementation of which is specific to a specific client module or deployment scenario.

If I understood correctly, @Qualifier determines which implementations of the target bean are injected into Injection points.

on the other hand, @Alternative describes a client-specific wish during deployment regarding whether the alternative is up to the standard ("@default", I mean) bean to get an injection at the injection point.

Correctly?

+8
java dependency-injection cdi
source share
1 answer

Yes, that's right. You can think of qualifiers as the main weave that you set up at design time using annotations in your source code.

Alternatives allow you to overwrite this at runtime with the beans.xml file, a simple deployment artifact.

A typical scenario would be to use different beans.xml for different environments and thus enable layouts of alternatives for components that you do not want to run in local / integration environments.

+2
source share

All Articles