This is Third  part of CDI discussion.Please visit first part and part two,


@Alternative
In part two we seen @qualifier 's to resolve the unambiguous problem for one interface and more than on implementation. In qualifier helps to solve in development time. (i.e all meta information is stored in class files).
Another solution is @Alternative annotation solve the problem in deployment time. all configuration is stored in beans.xml in WEB-INF folder


We take same example what we discussed in last part 


one interface (Hello) and two implementation(HelloImplOne, HelloImplTwo)
here i marked @Alternative in both implementation




Hello Interface



HelloImplOne Implementation




HelloImplTwo Implementation


and go and modify the beans.xml in WEB_INF folder



In <alternatives> tag in beans.xml we need specify which one need to inject.

See the screen cast for demo





Comments are welcomed