Problem
If you provide two implementations within your WAR or EAR file for just one interface and inject it using this code
@EJB
private MyInterface myInterface;
private MyInterface myInterface;
the application server will complain as soon as you try to deploy your archive; e.g. Glassfish throws an exception looking something like that:
Cannot resolve reference Remote ejb-ref name=at.rt.ClientBean/myInterface,Remote 3.x interface =at.rt.sameinterface.MyInterface,ejb-link=null,lookup=,mappedName=, jndi-name=,refType=Session because there are 2 ejbs in the application with interface at.rt.sameinterface.MyInterface.
Solution
If you want to keep your annotation, simply use the following code to resolve the lookup problem:
@EJB(beanName="MyInterfaceOneBean")
private MyIntterface myInterface;
private MyIntterface myInterface;
The other possibility is to modify your deployment descriptor and add an entry similar to that:
<ejb-jar ...>
<enterprise-beans>
<session>
<ejb-name> ClientBean </ejb-name>
<ejb-local-ref>
<ejb-ref-name>at.rt.ClientBean/myInterface</ejb-ref-name>
<local>at.rt.sameinterface.MyInterface </local>
<ejb-link>MyInterfaceOneBean</ejb-link>
</ejb-local-ref>
</session>
</enterprise-beans>
<enterprise-beans>
<session>
<ejb-name> ClientBean </ejb-name>
<ejb-local-ref>
<ejb-ref-name>at.rt.ClientBean/myInterface</ejb-ref-name>
<local>at.rt.sameinterface.MyInterface </local>
<ejb-link>MyInterfaceOneBean</ejb-link>
</ejb-local-ref>
</session>
</enterprise-beans>
</ejb-jar>
No comments:
Post a Comment