[jboss-user] [EJB3] - Multiple session beans with the same interface

Leon Feijtel do-not-reply at jboss.com
Wed Jul 10 07:03:53 EDT 2013


Leon Feijtel [https://community.jboss.org/people/feijtel] created the discussion

"Multiple session beans with the same interface"

To view the discussion, visit: https://community.jboss.org/message/827305#827305

--------------------------------------------------------------
Hi,

I've searched the website and also tried finding an answer in the EJB3 spec, but haven't been able to find an answer.

Is it possible (is it even allowed??) to have multiple EJB3 session beans that implement the same interface? 

I'm currently migrating an application from JBoss 5 to JBoss 7.2.0 and running into the error: JBAS014546: more than one EJB found with a particular interface....

I've made a simple example to show you what is being done in the code of the application:

[code]
@Local
public interface TestBean {
}

@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{
}
[/code]

And the error I'm getting is this:
[code]
12:51:46,310 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC000001: Failed to start service jboss.deployment.subunit."coo-ear.ear"."coo-ejb-2.3.2-SNAPSHOT.jar".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.subunit."coo-ear.ear"."coo-ejb-2.3.2-SNAPSHOT.jar".INSTALL: JBAS018733: Failed to process phase INSTALL of subdeployment "coo-ejb-2.3.2-SNAPSHOT.jar" of deployment "coo-ear.ear"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:127) [jboss-as-server-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_21]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_21]
    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_21]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS014546: More than one EJB found with interface of type 'nl.makelaarsuite.coo.test.TestBean' for binding java:global/coo/TestBean2. Found: [View of type nl.makelaarsuite.coo.test.TestBean for org.jboss.as.ejb3.component.stateless.StatelessComponentDescription{serviceName=service jboss.deployment.subunit."coo-ear.ear"."coo-ejb-2.3.2-SNAPSHOT.jar".component.TestBean2}@4c08702a, View of type nl.makelaarsuite.coo.test.TestBean for org.jboss.as.ejb3.component.stateless.StatelessComponentDescription{serviceName=service jboss.deployment.subunit."coo-ear.ear"."coo-ejb-2.3.2-SNAPSHOT.jar".component.TestBean1}@5335bcdf]
    at org.jboss.as.ejb3.deployment.processors.EjbInjectionSource.getResourceValue(EjbInjectionSource.java:97)
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.addJndiBinding(ModuleJndiBindingProcessor.java:251)
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor$1.handle(ModuleJndiBindingProcessor.java:196)
    at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:54)
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.processClassConfigurations(ModuleJndiBindingProcessor.java:164)
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.deploy(ModuleJndiBindingProcessor.java:157)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:120) [jboss-as-server-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
    ... 5 more
[/code]

I can understand that it's not desirable to have the same interface being used on 2 session beans, but the interface in my application contains a number of methods and that interface is also used later on to perform actions on the session bean.

A solution that works is to create a separate interface for each bean that inherit from the interface that has been used (TestBean in the example)...but in the application I'm migrating there are many beans that implement this interface, so that would require me to write a lot of "empty" interface classes just to get this work.

I guess if the spec (or JBoss) doesn't allow it, I have no other choice. Just wondering if there is an accaptable solution...

Any help is greatly appreciated. Thanks!

Leon
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/827305#827305]

Start a new discussion in EJB3 at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130710/b49c0fab/attachment-0001.html 


More information about the jboss-user mailing list