Discussions

EJB programming & troubleshooting: JBoss JNDI problem

  1. JBoss JNDI problem (2 messages)

    Hi, I use JBoss and write a simple stateless session bean
    the bean is called by an Struts' Action class and the code look like:

    InitialContext ctx = new InitialContext();
    Object objref = ctx.lookup("MyTestSessionBean");
    ...
    ...

    and my jboss.xml is:
    ...
    ...
    <session>
    <ejb-name>MyTestSession</ejb-name>
    <jndi-name>MyTestSessionBean</jndi-name>
    </session>
    ...
    ...

    It works very well but I want to know why the JNDI look up is:
    Object objref = ctx.lookup("MyTestSessionBean"); instead of
    Object objref = ctx.lookup("java:comp/env/ejb/MyTestSessionBean"); ?

    is it something a shorthand or JBoss has done some work for me?

    and what difference between the above 2 calls?

    If I use the first one, how can I refer to a bean which is in another machine?

    what happpen if my application scale up to cluster? do the first method sill work??

    finally, why my web.xml don't need to declare a <ejb-ref> to MyTestSessionBean in order to use it? I am a little confuse about this tag...

    any help would be appreciate

    Best regards

    Threaded Messages (2)

  2. JBoss JNDI problem[ Go to top ]

    Hi!

    Looks like the JBoss team has implemented without "java:comp/env/" in the beginning of the name. I know this from WebLogic Server 6.1 as well, while I know Apache requires the "java:comp/env/" prefix. I think the latter implementation is according to the specification. I strongly recommend everyone to write a service locator on top of all lookups. Then you only have to change the code in one line if there is a problem.

    I also have a comment on the following question:
    It works very well but I want to know why the JNDI look up is:
    Object objref = ctx.lookup("MyTestSessionBean"); instead of
    Object objref = ctx.lookup("java:comp/env/ejb/MyTestSessionBean"); ?
    Note that the "ejb" part of the name must be defined in the deploment descriptor. The "ejb" (and also the often proposed "jdbc") sub context is a recommendation. Not a requirement. Nothing will stop you from giving an EJB reference the name "jdbc/myEjb".

    /Tomas
  3. JBoss JNDI problem[ Go to top ]

    thanks a lot !!!
    after digging in the JBoss doc., you are right, JBoss DOESN'T allow external client to access JNDI tree with java:/ namespace

    thanks for help