aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark ""java:comp/env/" problem" Watch ""java:comp/env/" problem" New topic
Author

"java:comp/env/" problem

A Harry
Ranch Hand

Joined: Jan 23, 2002
Posts: 124
I have several (local) stateless session EJB's.

From my app I can get a reference to one using something like -

home = (EJBLocalHome) context.lookup("java:comp/env/ejb/ejb1");

but trying to get a reference to another one from a method within ejb1 I
have to use -

home = (EJBLocalHome) context.lookup("ejb/ejb2");

without the "java:comp/env/" bit otherwise I get a NamingException thrown

in my ejb-jar.xml I have -

<ejb-local-ref >
<ejb-ref-name>ejb/ejb2Local</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>uk.gov.ea.prd.interfaces.ejb2LocalHome</local-home>
<local>uk.gov.ea.prd.interfaces.ejb2Local</local>
<ejb-link>ejb2</ejb-link>
</ejb-local-ref>

I am completely stumped as to why this should happen - any ideas?

thanks

harry
Damanjit Kaur
Ranch Hand

Joined: Oct 18, 2004
Posts: 346
I have several (local) stateless session EJB's.

From my app I can get a reference to one using something like -

home = (EJBLocalHome) context.lookup("java:comp/env/ejb/ejb1");

but trying to get a reference to another one from a method within ejb1 I
have to use -

home = (EJBLocalHome) context.lookup("ejb/ejb2");

without the "java:comp/env/" bit otherwise I get a NamingException thrown


This must be happening because all different types of beans are maintained in separate container like Entity beans in different and Session Beans in different and so on. Specifying java:comp/env/ejb means specifying the environment for the component, where it should be looked for, i.e. in ejb. But this environment is already set in case when you try to access a EJB from another EJB, you don't need to specify java:comp/env/ejb again but only the lookup name as mentioned in xml file. As for accessing EJB from Session Bean or from Struts, you have to specify the component environment where to look for the ejb bean, along with its name mentioned in xml file because now you are accessing an entity Bean which lies in another container and not within same container where session Beans are.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "java:comp/env/" problem