1 Reply Latest reply on Apr 24, 2008 7:38 AM by jaikiran pai

    Binding the same session bean to JNDI more than once

    Colin Eberhardt Newbie

      Hi All,

      I want to deploy two distinct instances of my code in the same container.

      Therefore, I have a session bean (actually quite a few of them) that I want to bind to different JNDI names. Here is how I do it:

      My EJB3 code is packaged within a JAR file, which is itself packaged within an EAR (via. maven). I can configure the build to produce two different EARs:

      code1.ear
      code2.ear

      My session beans use the @RemoteBinding to specify the JNDI bindings.

      What happens is this:

      If I specify a JNDI binding for a session bean, then package within an ear, code1.ear, then deploy, I can see that it the binding is correct (via the JNDI View MBean).

      I then chance the JNDI binding by editing the @RemoteBinding, then re-package as code2.ear and deploy to the server.

      However, when I inspect JNDI View, the new binding has not occured.

      Interestingly, if I omit the @RemoteBinding annotation altogether, the container provides default bindings and I can see the two distinct bindings:

      code1/myBean
      code2/myBean

      Why, if I manually try to specify two distinct JNDI bindings for the same session bean (packaged within two different EARs), does the binding for the second EAR, when deployed, get ignored?

      I have tried using the corresponding XML equivalent to @RemoteBinding, again, without success.

      Regards.
      Colin E.

        • 1. Re: Binding the same session bean to JNDI more than once
          jaikiran pai Master

          You probably have not configured classloader isolation for those 2 EARs. Create a jboss-app.xml (if you don't have one, already) for both these EARs. The jboss-app.xml needs to be placed in the META-INF folder of the EARs. The contents of that file should be something like this:

          EAR1:

          <jboss-app>
           <loader-repository>
           org.myapp:loader=myEAR
           <loader-repository-config>
           java2ParentDelegation=false
           </loader-repository-config>
           </loader-repository>
          
          
          
          </jboss-app>
          


          For the other EAR, the jboss-app.xml contents will be similar except a unique name for the classloader

          EAR2:

          <jboss-app>
           <loader-repository>
           org.myapp:loader=myOtherEAR
           <loader-repository-config>
           java2ParentDelegation=false
           </loader-repository-config>
           </loader-repository>
          
          
          
          </jboss-app>