when you use beans.xml to enable/select an alternative it's only selected locally, i.e. in the bean archive where the beans.xml resides.
@Priority, on the other hand, selects the alternative globally, i.e. the alternative is selected for the application. How does you deployment look like? Is the beans.xml located in the same bean archive as the bean which attempts to inject a Validator?
Thank you for your answer.
My answer is: No. The interface, primary bean and mock is in Common.jar. The beans.xml in war.
I tried that way: The interface, primary bean is in Common.jar. The beans.xml and mock are in war. But it doesn't work too.
We have many maven profile in WAR build. And some profile use different alternative set. And thees profiles copy own beans.xml to the right place. This is why beans.xml located in war package.
since the enablement via beans.xml is on a per bean archive basis, you need to have that alternative defined in the beans.xml which resides in the same archive as the bean which does @Inject Validator.
Otherwise you need to use priority or probably leverage extensions in some way.
Where does the bean injecting Validor reside? In common.jar?
yes, in common.jar as well.
I see, that won't work. So you can either:
1) Keep the beans as they are and move your current beans.xml enablement into common.jar as well
2) Keep beans.xml in WAR but move bean which does @Inject Validator into WAR as well.
3) Use @Priority as a means of enabling alternative (but that has global effect)
Thanks you for your answers guys!