1 Reply Latest reply on Oct 20, 2011 3:38 PM by Bob Fields

    persistence.xml java:comp/env lookup fails during deployment

    Bob Fields Newbie

      I want to deploy the same unaltered war artifact in both JBoss AS7 (and ideally earlier) and in Tomcat7 and on other servers, those are just the main two. This is a code generation framework meant to be as generic as possible for all servers. The App is Spring3/Hibernate3/JSF12. I have modified versions of the same app working properly on both, with different jndi datasource names, but the sticking point is the JNDI lookup configured in the Spring JTA template. I want no jboss specific values (such as java:jboss in JNDI) in files used on multiple servers (Spring configuration, web.xml), however server-specific files such as tomcat context.xml and jboss jboss-web.xml which are ignored by all other servers are perfectly fine.

       

      Because of Tomcat limitations described in http://codepitbull.wordpress.com/2011/07/08/tomcat-7-with-full-jta/, the jndi datasource lookup java:comp/env needs to work properly because it must be configured as jdbc/datasource in web.xml, which means that is the format that I need to use in Spring and in web.xml. I can't get the java:comp/env lookup to work properly in JB7 when deploying the app. http://blog.vinodsingh.com/2008/12/jndi-lookup-on-tomcat-and-jboss-using.html and many others say the correct configuration is to use the tomcat configuration and map to the correct jndi lookup using jboss-web.xml.

       

      The JNDI datasource is configured as java:/jdbc/timetracker in standalone.xml, and lookups to that name work correctly when configured that way in spring. The actual JNDI datasource configuration can be changed to anything that will work with the standard spring and web.xml configurations.

       

      My web.xml:

      <resource-ref id="TimeTracker">

          <!-- Should be able to look this up as java:comp/env/jdbc/timetracker -->

          <res-ref-name>jdbc/timetracker</res-ref-name>       

          <res-type>javax.sql.DataSource</res-type>

          <res-auth>Container</res-auth>

          <res-sharing-scope>Shareable</res-sharing-scope>

          <!-- Point to the jndi name of the datasource -->

          <lookup-name>jdbc/timetracker</lookup-name>

      </resource-ref>

       

      My jboss-web.xml:

      <jboss-web>

            <resource-ref>

               <res-ref-name>jdbc/timetracker</res-ref-name>

               <jndi-name>java:/jdbc/timetracker</jndi-name>

            </resource-ref>

      </jboss-web>

       

      But I still get the error when deploying, like it can't do the java:comp/env/jdbc lookup:

      n step-2" => {"Services with missing/unavailable dependencies" => ["jboss.naming

      .context.java.module.\"timetracker-web-3.4-SNAPSHOT\".\"timetracker-web-3.4-SNAP

      SHOT\".env.jdbc.timetracker missing [ jboss.naming.context.java.jboss.resources.

      jdbc.timetracker ]","jboss.persistenceunit.\"timetracker-web-3.4-SNAPSHOT.war#ti

      metracker\" missing [ jboss.naming.context.java.comp.\"timetracker-web-3.4-SNAPS

      HOT\".\"timetracker-web-3.4-SNAPSHOT\".\"timetracker-web-3.4-SNAPSHOT\".env.jdbc

      .timetracker ]"]}}}

       

      I've tried many different configurations in jboss-web resource-ref such as java:comp/env/jdbc/timetracker, java:/jdbc/timetracker, java:jdbc/timetracker, jdbc/timetracker. All I want to do is get a valid datasource lookup from java:comp/env/jdbc/timetracker.

       

      If I change META-INF\persistence.xml from

      <jta-data-source>java:comp/env/jdbc/timetracker</jta-data-source>

      to

      <jta-data-source>java:/jdbc/timetracker</jta-data-source>

       

      and make the same change in Spring applicationContext.xml from

      <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">

          <property name="jndiName" value="java:comp/env/jdbc/timetracker"/>

      </bean>

       

      then the lookups work fine and the application deploys and runs without error.

       

      Latest released versions of everything: AS7.0.2, Hibernate 3.6.7, Spring 3.0.6.

       

      This would be a whole lot easier if AS7 simply recognized the java:comp/env/jdbc lookup as a datasource lookup automatically mapped to java:/jdbc or java:jboss/jdbc for backwards compatibility.

        • 1. Re: JNDI/web.xml configuration which works for both JB7 and Tomcat7?
          Bob Fields Newbie

          Looks like a bug with the way JBoss reports contextInitialized before it is truly initialized, http://community.jboss.org/message/570071#570071 pointed me in the right direction. Hibernate does the same thing as Spring during initialization, so I was able to reproduce this problem even after removing all of the Spring configuration, with only a persistence.xml file referring to the java:comp/env datasource.

          AS6.1 reports a similar error, and also works with the global datasource.

           

          I attached a very small project containing only the persistence.xml and web.xml and jboss-web.xml files, pointing to the built-in AS7 ExampleDS datasource. It results in the following error during deployment:

          14:22:39,605 ERROR [org.jboss.as.deployment] (DeploymentScanner-threads - 1) {"Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"JavaCompEnvContextBug.war#ExampleDS\" missing [ jboss.naming.context.java.comp.JavaCompEnvContextBug.JavaCompEnvContextBug.JavaCompEnvContextBug.env.jdbc.ExampleDS ]"]}}}

           

          If you change persistence.xml to point to the global datasource, it deploys OK, and you can run localhost:8080/JavaCompEnvContextBug/jndiBean.jsp to verify that the java:comp/env datasource works correctly.

           

          Created bug report https://issues.jboss.org/browse/AS7-2184