JBoss Community

Re: Multiple session beans with the same interface

created by jaikiran pai in EJB3 - View the full discussion

It's perfectly valid for multiple EJBs to implement the same interface. The error isn't because multiple EJBs are implementing the same interface, but it's because the usage of the @EJB in your application is such that the container has no idea which of the multiple EJB implementations you are trying to setup into the java:global namespace via the @EJB usage:

 

@Stateless
@EJB(name = "java:global/coo/TestBean1", beanInterface = TestBean.class)
public class TestBean1 implements TestBean{
}
 
@Stateless
@EJB(name = "java:global/coo/TestBean2", beanInterface = TestBean.class)
public class TestBean2 implements TestBean{

 

The spec allows you to narrow it down to the specific EJB implementation. You can do so by using the "beanName" attribute of the @EJB where you can specify the name of the bean (which by default is the bean implementation's simple class name). So you should change that above code to:

 

@Stateless

@EJB(name = "java:global/coo/TestBean1", beanInterface = TestBean.class, beanName="TestBean1")

public class TestBean1 implements TestBean{

}

 

@Stateless

@EJB(name = "java:global/coo/TestBean2", beanInterface = TestBean.class, beanName="TestBean2")

public class TestBean2 implements TestBean{

Reply to this message by going to Community

Start a new discussion in EJB3 at Community