I have no problem calling my EJB from client App, but when I try to read value in environment entries it fails with the following message :
javax.naming.NameNotFoundException: No object bound for java:comp/env
My code is :
Context Init = new InitialContext();
Context Env = (Context)Init.lookup("java:com/env");
I've set a value in environment entries tab in Deploytool.
What's wrong ? Please help.
Sorry, I did type "comp" in my program, it's only a typho in this forum because the error message says "java:comp/env".
I also have EJB on the server with JNDI name ejb/SecurityBean when I call it just "ejb/SecurityBean" it works fine, but when I call it with full path specification "java:comp/env/ejb/SecurityBean" it produces the same error as above.
Add <ejb-ref>...</ejb-ref> in your web.xml file if you call the EJB from an Servlet.
Is it your Session Bean that is trying to lookup java:comp/env? or the TestClient? The error looks like the test client program is trying to do the lookup. Only the bean itself will be able to see the magical java:comp/env.
Yeah, I think this changed with the change from the 1.1 to 1.2 spec. In older client programs looking up EJBs the default was always that they were under comp/env, but now they just are at wherever you put them. So, for instance, if you are using weblogic and you put this in your weblogic-ejb-jar.xml file for the bean:
You get it back like:
Object ref = jndiContext.lookup("TestBean");
Yes, I try to lookup from TestClient, so I guess this is the mistake ?
Yeah. The "java:comp/env" context is a magical one.
Imagine if two EJBs have a value they want to store called "host". They can set that up in the <env-entry>'s
Bean A: host=hostA.com
Bean B: host=hostB.com
although the JNDI name for each bean to get this entry is the same: java:comp/env/host
Each one will get the right value (its own).
This is all due to the fact that java:comp/env is special for J2EE components. A normal client will not be able to find a reference, environment entry, or what have you via that context. That is why the test client isn't finding anything... it would need the *real* jndi name, not the reference
Thanks a lot Mr. Dion for your explanation,
I understand now, but since now I can retrieve the value, how can I change the present value or add new ones programmatically ?
I am sorry...this might be a little late.
But could you tell me how you resolved this problem?