4 Replies Latest reply on Jan 2, 2004 10:13 AM by Frank Griffin

    How to look up a bean in another JBoss' JNDI ?

    Frank Griffin Novice

      This has got to be a common question, but the searches I've tried either get nothing or the universe, so I'll just ask...

      I have a situation where my application distributes session-bean work to multiple JBoss servers on multiple hosts, but the entity EJBs which define distributed requests and keep their state live on only one of these servers. Reasons for sending MDB or session EJB work to servers other than the one hosting the entity beans include access to resources specific to a remote platform (type I/II JDBC drivers).

      Any session EJBs on the server which hosts the entity EJBs have no problem: whether the deployment descriptor uses the local or remote interface, the entity bean is defined in the default JNDI used by the session bean, because they are both using the same JNDI.

      My question involves the other servers. Obviously the deployment descriptor for the session bean must use the remote interface for the entity bean. But how do you tell JBoss to look up a remote entity bean in another JBoss' JNDI ? Is this done at the bean level for each referenced entity bean, or is it a higher-level operation where you map some part of the JNDI namespace of one server to a remote JNDI ?

      Thanks for any help.

        • 1. Re: How to look up a bean in another JBoss' JNDI ?
          sudsy Newbie

          Everything derives from the InitialContext which you use to perform lookups. Check out this code:
          Hashtable env = new Hashtable();
          Context ctx = new InitialContext( env );
          This assumes that you're running the default JBoss naming service on a host known as somehost at the default port (1099). Now you can just use ctx in the usual manner, i.e.:
          Object obj = ctx.lookup( "someclass" );
          Be sure to use PortableRemoteObject.narrow() rather than just a simple cast as you're dealing with a remote reference here.

          • 2. Re: How to look up a bean in another JBoss' JNDI ?
            Frank Griffin Novice

            Thanks for the reply.

            I know the actual JNDI mechanics of doing this, but I was looking for a way to do it outside of the code, e.g. in the deployment descriptor or in the JBoss configuration files. I don't want the code to have to particpate in JNDI management.

            Section 19.7 of the spec states that the container must take care of linking an <ejb-ref> to the InitialContext of the owning server, but doesn't say where to specify the server. I'm assuming that the way to do it is container-specific, so basically what I'm asking is how to tell JBoss to do it...

            • 3. Re: How to look up a bean in another JBoss' JNDI ?
              Jon Barnett Master

              For your ejb-ref tag set in jboss.xml, try:


              I haven't tried it in a while but it should work. You then use the ejb-ref in your lookup.
              ... ctx.lookup("java:comp/env/ejb/SomeBean");

              You'll need to create the appropriate ejb-ref tags in ejb-jar.xml to complete the mapping.

              This, as with the original suggestion, only works with communication using the same JBoss version servers - due to the requirements of Java class versioning imposed by the client-server communication.

              Refer to http://amitysolutions.com.au/documents/JBossTomcatJNDI-technote.pdffor more information on reference mappings.

              Hope that helps.

              • 4. Re: How to look up a bean in another JBoss' JNDI ?
                Frank Griffin Novice

                Sounds promising; I'll try it. Thanks for the post.