about initial context
2 posts in topic
Flat View  Flat View

Posted By:   nimit_shah
Posted On:   Monday, July 1, 2002 04:58 AM

I don't understand why to use and how to use 'java:compenvejb ean name', while getting initial context.When I refer to bean using only JNDI name, it gives proper output, but if I use java:compenvejbJNDINAME it gives error at run time.

Re: about initial context

Posted By:   Viral_Shah  
Posted On:   Wednesday, July 3, 2002 10:30 PM

The java:comp/env/xxx type of lookup helps to decouple the ejb clients to the ejb's JNDI name. As must have observed, you *do not* specify the JNDI name for a EJB bean in the ejb-jar.xml, rather its specified in the container specific deployment descriptor. Using this pattern, we can allow the deployer to change the JNDI names for the bean for a particular installation. (Remember that EJB's are server-side components, and plug-n-play usage should always be expected)

As Garf has said very correctly, this type of lookup cannot be used for the look-up outside the container, but we can atleast make the local lookups decoupled from the JDNI names.


Re: about initial context

Posted By:   Gautam_Marwaha  
Posted On:   Monday, July 1, 2002 05:24 AM

java:com/env is the Context root of the JNDI tree the container provides to the deployed EJBs. To access JNDI resources from within beans either prefix all JNDI names with "java:com/env" prefix OR get InitialContext with blank constructor and lookup "java:com/env". From the context returned access JNDI resources by JNDI name only

However, when accessing a deployed bean from OUTSIDE a container, say a client program, then you will first need to obtain InitialContext from the server passing proper user credentials as args (Hashtable I think) and using the InitialContext perform JNDI lookup with EJB JNDI name (no java:comp/env reqd.)
About | Sitemap | Contact