When locating resources, such as a DataSource, why is the jndi name of the resource prefixed with java:comp/env?
For example, given a DataSource jdbc/datasource why do we use java:comp/env/jdbc/datasource instead of just jdbc/datasource?
All EJBs have a default JNDI context called the environment context. The default context exists in the name space called "java:comp/env" and its subdirectories. When the bean is deployed, any beans it uses are mapped into the subdirectory "java:comp/env/ejb".
Furthermore, The EJB specification recommends that all resource manager connection factory references be organised in the subcontexts of the bean�s environment, using a different subcontext for each resource manager type. So, typically you get this:
java:comp/env/jdbc - for
JDBC DataSource references
java:comp/env/jms - for JMS connection factories
java:comp/env/mail - for JavaMail connection factories
java:comp/env/url - for URL connection factories