users@glassfish.java.net

Re: JNDI question

From: Cheng Fang <Cheng.Fang_at_Sun.COM>
Date: Tue, 23 Oct 2007 21:05:23 -0400

> I think I already knew most of that and I am using injections to get, for example, db connections already. But what I don't understand even after reading your post why I can't do ctx.lookup("java:comp/env/something") in a method running within my container but only ctx.lookup("something")?

Because you haven't declared a <ejb-ref>, <resource-ref> or
<resource-env-ref> in deployment descriptors, nor have you injected it
into component classes. If you are talking about outside appserver,
"java:comp/env/something" will not work in Java SE standalone
applications, since there is no container to provide JNDI service. Some
code example may help me better understand the issue.


> Do you mean that when I use the admin console I only assign it a physical name and not a logical name?
>

When you create a resource or deploy an EJB module, you assign it a
physical jndi-name, which is scoped to the appserver. There is no
logical name yet. A logical name is declared and mapped to a physical
name in your application. So the logical name is scoped to the
application (the webapp, or an EJB).