Java – is it not allowed to implement a single local interface by two stateless beans

ejb-3.0java

I am getting following exception when a Local Interface is implemented by two Stateless beans, in which one having normal functionality and other having some enhanced functionality in it.

java.lang.RuntimeException: could not
resolve global JNDI name for @EJB for
container UserBean: reference class:
org.app.SecurityServiceLocal ejbLink:
duplicated in Some.jar

Best Answer

Finally I came to know why I am getting this exception

I have used @EJB annotation to inject a Stateless bean into another Stateless bean Name UserBean with following code

@Stateless(name="UserBean")
@EJB(name="app/SecurityService",
        beanInterface=SecurityServiceLocal.class)
public class UserBean implements UserRemote{

}

If you check the injection details I was injecting SecurityServiceLocal, which was implemented by two Stateless bean classes name SercurityServiceBean and SecurityServiceEnhaBean. So, container is in ambiguity state to decide which bean to inject in as both are implementing same interface.

This can be resolved by specifying some more information like beanName property value in @EJB annotation. There you need to provide which stateless bean class needs to be injected by using bean name(declared at that bean level (or) in ejb-jar.xml). check the code to identify the change in the injection mapping

@Stateless(name="UserBean")
@EJB(name="app/SecurityService",
        beanInterface=SecurityServiceLocal.class,
        beanName="SecurityServiceEnha")
public class UserBean implements UserRemote{

}
Related Topic