2 Replies Latest reply on Nov 25, 2003 8:23 PM by nickmo

    Cannot lookup Datasource under comp/env

    nickmo

      I 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

        • 1. Re: Cannot lookup Datasource under comp/env
          jonlee

          Could you explain your set up? I might be a bit slow here, but are you using an embedded Tomcat in JBoss 3.2 or is this a standalone Tomcat? You show the server.xml fragment but I am assuming you are moving to the embedded Tomcat that doesn't use server.xml. So correct me if the assumption is wrong.

          Based on these assumptions, you need to bundle a jboss-web.xml into your WAR, and add a resource reference if it is not there in web.xml:

          <resource-ref >
           <res-ref-name>PostgresDB</res-ref-name>
           <res-type>javax.sql.DataSource</res-type>
           <res-auth>Application</res-auth>
           </resource-ref>

          jboss-web.xml:
          <resource-ref>
           <res-ref-name>PostgresDB</res-ref-name>
           <jndi-name>java:/PostgresDS</jndi-name>
           </resource-ref>


          Greater depth can be found in http://www.amitysolutions.com.au/documents/JBossJNDI-technote.pdf. Hope that helps but I made a few assumptions on your configuration.

          • 2. Re: Cannot lookup Datasource under comp/env
            nickmo

            Thanks for your help. Actually, the opposite is the case. We are moving from an embedded Tomcat to a standalone version for which case I am using the server.xml file for configing the virtual hosts and Tomcat datasources.

            With the embedded Tomcat (current Jboss/Tomcat distribution) I was not experiencing the aforementioned difficulties. I was able to set up and manipulate datasources rather easily. With the embedded version I was able to access my datasource from both Tomcat and JBoss using the "java:/PostgresDB" JNDI name.

            For various reasons it became problematic using the embedded version which leads me to the current issues configuring the datasource for JBoss.

            Any additional insight would be much appreciated, thanks.