Annotation @Alternative does not work properly in EJB
Issue
I am using @Alternative annotation for testing purposes and it doesn't working properly. The default implementation is always injected:
- Interface
public interface MyService
- Default implementation
public class DefaultServiceImpl implements MyService
- Alternative implementation
@Alternative
public class AlternativeServiceImpl implements MyService
- Stateless EJB
@Stateless
public class MyBO {
@Inject
private MyServcie myService
...
}
- beans.xml
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<alternatives>
<class>xxx.AlternativeServiceImpl</class>
</alternatives>
</beans>
Environment
- Red Hat JBoss Enterprise Application Platform 6.3.1
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
