Discussions

General J2EE: Confused by the namespace of JNDI when lookup Bean!

  1. Confused by the namespace of JNDI when lookup Bean! (1 messages)

    Confused by the namespace of JNDI when lookup Bean!

    Hi:
      I really confused by the call parameter of JNDI's lookup.

      if client call BeanA, which one is correct?
        the first one is: Object ref=InitialContext(properties).lookup("BeanA")
        the second one is: Object ref=InitialContext(properties).lookup("java:comp/env/ejb/BeanA")
        the third one is: Object ref=InitialContext(properties).lookup("java:comp/env/BeanA")

      if BeanB call BeanA in the same VM, which one is correct?
        the first one is: Object ref=InitialContext().lookup("BeanA")
        the second one is: Object ref=InitialContext().lookup("java:comp/env/ejb/BeanA")
        the third one is: Object ref=InitialContext().lookup("java:comp/env/BeanA")

      Why?
      

    Thanks!
    John Lee
  2. The essence of "java:comp/env" is a frequent subject...

    Basically the private naming context java:comp/env is used to provide a layer of abstraction regarding dependencies on external resources.

    For example, if CarEJB needs a reference to EngineEJB in order to work, java:comp/env can be used to hide the real JNDI name of EngineEJB from CarEJB. CarEJB uses "java:comp/env/EngineEJB" to access EngineEJB even though EngineEJB is really deployed using the real JNDI name "com.company.Engine".

    This is made possible by mapping the "private" and "real" JNDI name with the deployment descriptors. This way, if you for some reason cannot deploy EngineEJB with the real JNDI name "com.company.Engine", you don't need to recompile, only reconfigure.