Cannot lookup Datasource under comp/env
nickmo Nov 25, 2003 4:33 PMI am in the process of upgrading from JBoss 2
to JBoss 3 and I am having difficulty looking
up a PostgreSQL
datasource under the "java:/comp/env" subcontext
from within the container, particularly from
within a session bean. Our previous installation
was a jboss2.x/tomcat3.x bundle whereas currently
I will be deploying the services independently
for various reasons.
I understand that the
datasource should be registered as the name of the
datasource only, not prefaced by "comp/env", in
the "-ds.xml" datasource configuration file.
Code snippet postgres-ds.xml:
<local-tx-datasource>
<jndi-name>PostgresDB</jndi-name>
<connection-url>jdbc:postgresql://localhost/imdb</connection-url>
....
Since
I am deploying my beans under CMP1.1, I continue
to use the jaws.xml deployment descriptor where
I also have the the datasource referenced for the
sake of the EJB's. (At this time it is too costly
for us to make the full upgrade to CMP2.0 but plan
to in the future).
Code snippet jaws.xml:
java:/PostgresDB
<type-mapping>PostgreSQL</type-mapping>
....
Under Tomcat 4 I have the datasource configured
as follows:
Code snippet server.xml:
factoryorg.apache.commons.dbcp.BasicDataSourceFactory
driverClassNameorg.postgresql.Driver
urljdbc:postgresql://localhost/imdb
....
...later on with a of a virtual host:
The following is an example of a working lookup in
Tomcat (such as a JSP or business delegate):
Context ctx = new InitialContext();
DataSource d = (DataSource) ctx.lookup("java:/comp/env/PostgresDB");
As far as JBoss goes, the EJB's appear to deploy without
a problem, but when it comes to calling on a session
bean that makes a JDBC call, the datasource cannot be
found under "java:/comp/env/PostgresDB". For the sake
of the maintenance of our system, it is IMPORTANT that
the JNDI name for the datasource remain constant between
Tomcat and JBoss for use in jdbc queries, as it is
requested from a shared configuration file.
Reading the documentation, it appears that I should be
able to reach the datasource under the "java:/comp/env/PostgresDB"
name but I have thus far been unable to do so.
Is there something that I am missing? I have tooled around
with the jboss.xml file but have been unable to have that
lead to any breakthroughs.
Thanks in advance!
-nickmo