Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CDI : @alternative vs @Qualifiers

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 ?

like image 409
arthur Avatar asked Aug 28 '12 19:08

arthur


1 Answers

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.

like image 60
Jan Groth Avatar answered Oct 23 '22 08:10

Jan Groth