• Post Reply Bookmark Topic Watch Topic
  • New Topic

when to use "java:comp/env" to lookup a bean  RSS feed

 
Skripi Mayer
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I started EE Unit Testing with junit and junitee and tried to lookup a EJB
from within my TestCase. Remote Beans work fine with
InitialContext().lookup("[BEANNAME]"),
but he wouldn't dare to find my local Bean. Changing the lookup to
InitialContext().lookup("java:/comp/env/[BEANNAME]") worked instead.

Also the RI Deployment tool seems to ignore all Parameters (like ejb-refs)
set in a generated war archive (at least it doesn't show them in the GUI).

Any ideas for those two ?
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on what you specify as the jndi name to bind your bean to, you should be just fine. It is most often more than just the bean name. You should consult the RI documentation for the default jndi name beans are bound to. (Or better yet, you can specify it yourself).
 
Frederico Melo
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is one of the most misunderstood things on JNDI specification. The naming context should provide two different trees: the remote naming context and local enviroment context. (there are another names for the same things too)

the enviroment(comp/env) should only be used and be visible for components inside the same container of the naming context provider. So, your local interfaces should be located using the fully qualified name on the enviroment context:
java:comp/env/ejb/<EJB_NAME>
The same approach should be used for another components, like Datasources and stuff. (java:comp/env/jdbc/<DATASOURCE> for example)

Your remote objects instead should be located directly using it's names
<EJBNAME> or <DATASOURCE> for example.

The reason for this so misunderstood topic is that some servers let components inside and outside container lookup references on both contexts without any warning of spec compliance break.

Some specific application servers, like Websphere and Weblogic follows the spec rules and doesn't let you lookup references without specifing java:comp/env inside the container..

regards,

Fred
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!