3 Replies Latest reply on Sep 30, 2008 10:03 AM by Sandor Fiedler

    Multiple EJBs with same name in different jars - deployment

    jaikiran pai Master

      I have an EAR file containing 2 ejb jar files. Each of the jar files has one EJB3.0 Stateless bean each:

      MyApp.ear
      |
      |--- META-INF
      | |
      | |--- application.xml
      | |
      | |--- jboss-app.xml
      |
      |
      |--- appOneEjb.jar
      | |
      | |--- org/myapp/AppManagerBean.class
      |
      |
      |--- appTwoEjb.jar
      | |
      | |--- org/myapp/AppManagerBeanV2.class
      |
      |
      |--- common.jar
      | |
      | |--- org/myapp/AppManager.class
      
      


      Both these stateless beans (AppManagerBeanV2.class and AppManagerBean.class) implement the same AppManager.class and more importantly the "name" attribute of the @Stateless annotation for both these beans is the same. However, these 2 beans are packaged in different jar files inside an EAR:


      @Stateless (name="mybean")
      @Remote (AppManager.class)
      public class AppManagerBeanV2 implements AppManager {
      
       public String getVersion() {
       return "2.0";
       }
      
      }
      



      @Stateless (name="mybean")
      @Remote (AppManager.class)
      public class AppManagerBean implements AppManager {
      
       public String getVersion() {
       return "1.0";
       }
      
      }
      


      I could not find much documentation on the name attribute of @Stateless. But since the "name" is equivalent to the ejb-name in the ejb-jar.xml, i guess, the following (from the ejb-jar.xml dtd) holds true:

      The ejb-name element specifies an enterprise bean's name. ... The name must be unique among the names of the enterprise beans in the same ejb-jar file.


      So as per this definition, i guess i can have multiple EJBs with the same name, but in different jar files (as in my sample application). But when i deploy, this on JBoss-5 CR2 i get the following exception during deployment:


      17:01:35,311 INFO [JBossASKernel] Created KernelDeployment for: another_ejb3.jar
      17:01:35,311 INFO [JBossASKernel] installing bean: jboss.j2ee:ear=ZEJB3Persistence.ear,jar=another_ejb3.jar,name=mybean,service=EJB3
      17:01:35,311 INFO [JBossASKernel] with dependencies:
      17:01:35,311 INFO [JBossASKernel] and demands:
      17:01:35,311 INFO [JBossASKernel] jboss.ejb:service=EJBTimerService
      17:01:35,311 INFO [JBossASKernel] and supplies:
      17:01:35,311 INFO [JBossASKernel] jndi:AppManagerRemoteV2
      17:01:35,311 INFO [JBossASKernel] Class:org.myapp.ejb.AppManager
      17:01:35,311 INFO [JBossASKernel] jndi:ZEJB3Persistence/mybean/remote-org.myapp.ejb.AppManager
      17:01:35,311 INFO [JBossASKernel] jndi:ZEJB3Persistence/mybean/remote
      17:01:35,311 INFO [JBossASKernel] Added bean(jboss.j2ee:ear=ZEJB3Persistence.ear,jar=another_ejb3.jar,name=mybean,service=EJB3) to KernelDeployment of: another_ejb3.jar
      17:01:35,779 INFO [JBossASKernel] Created KernelDeployment for: myapp_ejb3.jar
      17:01:35,795 INFO [JBossASKernel] installing bean: jboss.j2ee:ear=ZEJB3Persistence.ear,jar=myapp_ejb3.jar,name=mybean,service=EJB3
      17:01:35,795 INFO [JBossASKernel] with dependencies:
      17:01:35,795 INFO [JBossASKernel] and demands:
      17:01:35,795 INFO [JBossASKernel] jboss.ejb:service=EJBTimerService
      17:01:35,795 INFO [JBossASKernel] and supplies:
      17:01:35,795 INFO [JBossASKernel] Class:org.myapp.ejb.AppManager
      17:01:35,795 INFO [JBossASKernel] jndi:ZEJB3Persistence/mybean/remote-org.myapp.ejb.AppManager
      17:01:35,795 INFO [JBossASKernel] jndi:AppManagerRemote
      17:01:35,795 INFO [JBossASKernel] jndi:ZEJB3Persistence/mybean/remote
      17:01:35,795 INFO [JBossASKernel] Added bean(jboss.j2ee:ear=ZEJB3Persistence.ear,jar=myapp_ejb3.jar,name=mybean,service=EJB3) to KernelDeployment of: myapp_ejb3.jar
      17:01:35,795 INFO [JBossASKernel] installing bean: jboss.j2ee:ear=ZEJB3Persistence.ear,jar=myapp_ejb3.jar,name=UserManagerBean,service=EJB3
      17:01:35,795 INFO [JBossASKernel] with dependencies:
      17:01:35,795 INFO [JBossASKernel] and demands:
      17:01:35,795 INFO [JBossASKernel] jboss.j2ee:ear=ZEJB3Persistence.ear,name=mybean,service=EJB3,*
      17:01:35,795 INFO [JBossASKernel] persistence.unit:unitName=ZEJB3Persistence.ear/myapp_ejb3.jar#EJB3Persistence
      17:01:35,795 INFO [JBossASKernel] jboss.ejb:service=EJBTimerService
      17:01:35,795 INFO [JBossASKernel] and supplies:
      17:01:35,795 INFO [JBossASKernel] Class:org.myapp.ejb.UserManagerRemote
      17:01:35,795 INFO [JBossASKernel] jndi:ZEJB3Persistence/UserManagerBean/local-org.myapp.ejb.UserManagerLocal
      17:01:35,795 INFO [JBossASKernel] Class:org.myapp.ejb.UserManagerLocal
      17:01:35,795 INFO [JBossASKernel] jndi:ZEJB3Persistence/UserManagerBean/local
      17:01:35,795 INFO [JBossASKernel] jndi:RemoteUserManagerBean
      17:01:35,795 INFO [JBossASKernel] jndi:ZEJB3Persistence/UserManagerBean/remote-org.myapp.ejb.UserManagerRemote
      17:01:35,795 INFO [JBossASKernel] jndi:testMappedNameJai
      17:01:35,795 INFO [JBossASKernel] Added bean(jboss.j2ee:ear=ZEJB3Persistence.ear,jar=myapp_ejb3.jar,name=UserManagerBean,service=EJB3) to KernelDeployment of: myapp_ejb3.jar
      17:01:37,186 INFO [SessionSpecContainer] Starting jboss.j2ee:ear=ZEJB3Persistence.ear,jar=another_ejb3.jar,name=mybean,service=EJB3
      17:01:37,201 INFO [EJBContainer] STARTED EJB: org.myapp.ejb.impl.AppManagerBeanV2 ejbName: mybean
      17:01:37,217 WARN [SessionSpecContainer] Populating JBoss-specific annotation metadata manually until done by deployers: jboss.j2ee:ear=ZEJB3Persistence.ear,jar=another_ejb3.jar,name=mybean,service=EJB3
      17:01:37,608 INFO [SessionSpecContainer] Starting jboss.j2ee:ear=ZEJB3Persistence.ear,jar=myapp_ejb3.jar,name=mybean,service=EJB3
      17:01:37,608 INFO [EJBContainer] STARTED EJB: org.myapp.ejb.impl.AppManagerBean ejbName: mybean
      17:01:37,608 WARN [SessionSpecContainer] Populating JBoss-specific annotation metadata manually until done by deployers: jboss.j2ee:ear=ZEJB3Persistence.ear,jar=myapp_ejb3.jar,name=mybean,service=EJB3
      17:01:37,639 INFO [SessionSpecContainer] Stopping jboss.j2ee:ear=ZEJB3Persistence.ear,jar=myapp_ejb3.jar,name=mybean,service=EJB3
      17:01:37,639 INFO [EJBContainer] STOPPED EJB: org.myapp.ejb.impl.AppManagerBean ejbName: mybean
      17:01:37,670 ERROR [AbstractKernelController] Error installing to Start: name=jboss.j2ee:ear=ZEJB3Persistence.ear,jar=myapp_ejb3.jar,name=mybean,service=EJB3 state=Create
      java.lang.RuntimeException: Could not bind Reference Class Name: Proxy for: org.myapp.ejb.AppManager
      Type: ProxyFactoryKey
      Content: ProxyFactory/AppManagerRemote
      Type: EJB Container Name
      Content: jboss.j2ee:ear=ZEJB3Persistence.ear,jar=myapp_ejb3.jar,name=mybean,service=EJB3
      Type: Remote Business Interface
      Content: org.myapp.ejb.AppManager
      Type: Remoting Host URL
      Content: socket://ps3346:3873/?
       into JNDI at "ZEJB3Persistence/mybean/remote-org.myapp.ejb.AppManager"
       at org.jboss.ejb3.proxy.jndiregistrar.JndiSessionRegistrarBase.bind(JndiSessionRegistrarBase.java:694)
       at org.jboss.ejb3.proxy.jndiregistrar.JndiSessionRegistrarBase.bind(JndiSessionRegistrarBase.java:674)
       at org.jboss.ejb3.proxy.jndiregistrar.JndiSessionRegistrarBase.bind(JndiSessionRegistrarBase.java:641)
       at org.jboss.ejb3.proxy.jndiregistrar.JndiSessionRegistrarBase.bindEjb(JndiSessionRegistrarBase.java:165)
       at org.jboss.ejb3.session.SessionSpecContainer.lockedStart(SessionSpecContainer.java:706)
       at org.jboss.ejb3.stateless.StatelessContainer.lockedStart(StatelessContainer.java:220)
       at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:858)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:59)
       at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:150)
       at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction$JoinpointDispatchWrapper.execute(KernelControllerContextAction.java:241)
       at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:47)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:109)
       at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:70)
       at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:221)
       at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54)
       at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42)
       at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
       at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
       at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
       at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:774)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:540)
       at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:124)
       at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:51)
       at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
       at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
       at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:169)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1285)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1003)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1024)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1056)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:944)
       at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
       at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
       at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
       at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
       at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
       at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:627)
       at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:541)
       at org.jboss.system.server.profileservice.ProfileServiceBootstrap.loadProfile(ProfileServiceBootstrap.java:265)
       at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:143)
       at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:409)
       at org.jboss.Main.boot(Main.java:209)
       at org.jboss.Main$1.run(Main.java:544)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.naming.NameAlreadyBoundException
       at org.jnp.server.NamingServer.bind(NamingServer.java:165)
       at org.jnp.server.NamingServer.bind(NamingServer.java:130)
       at org.jnp.server.NamingServer.bind(NamingServer.java:130)
       at org.jnp.interfaces.NamingContext.bind(NamingContext.java:593)
       at org.jnp.interfaces.NamingContext.bind(NamingContext.java:554)
       at org.jboss.util.naming.Util.bind(Util.java:105)
       at org.jboss.util.naming.Util.bind(Util.java:91)
       at org.jboss.ejb3.proxy.jndiregistrar.JndiSessionRegistrarBase.bind(JndiSessionRegistrarBase.java:689)
       ... 55 more
      
      


      Am i doing the right thing by having multiple beans with the same name? If yes, then it looks like when creating the jndi names for the interface specific proxies, we might even have to include the jar name in the jndi name to avoid this exception.


        • 1. Re: Multiple EJBs with same name in different jars - deploym
          Sandor Fiedler Newbie

          HI jaikiran,

          the spec states (p.494):


          Binding of enterprise bean references. The Application Assembler may link an enterprise
          bean reference to another enterprise bean in the ejb-jar file or in the same Java EE application
          unit. The Application Assembler creates the link by adding the ejb-link element to the referencing
          bean. The Application Assembler uses the ejb-name of the referenced bean for the
          link. If there are multiple enterprise beans with the same ejb-name, the Application Assembler
          uses the path name specifying the location of the ejb-jar file that contains the referenced
          component. The path name is relative to the referencing ejb-jar file. The Application Assembler
          appends the ejb-name of the referenced bean to the path name separated by #. This
          allows multiple beans with the same name to be uniquely identified.


          As far as I would comment this; I would assume that it is the application assemblers responsibility to keep binding name unique within the scope of an application. In this case an application can be an ejb-jar or an ear.

          Regards
          \sandor\

          • 2. Re: Multiple EJBs with same name in different jars - deploym
            jaikiran pai Master

            Hi Sandor,

            These 2 beans are independent of each other and don't refer each other. Each one implements the same business interface and has the same "name" but provides a different implementation.

            • 3. Re: Multiple EJBs with same name in different jars - deploym
              Sandor Fiedler Newbie

              Hi jaikiran,

              again I would say it's the application assembler responsibility to make things unique. I would not expect any kind of automatism in this case.