6 Replies Latest reply on Aug 1, 2007 3:15 AM by zhjjava

    JBOSS,datasource jndi?In the init() mothod of HttpServlet's

    zhjjava

      Hi all!

      JBOSS,datasource jndi?datasource's config should be correct!But In the init() mothod of HttpServlet's instance I could not lookup datasource.

      env:
      jboss3.26+linux+jdk1.4.2?DB:oracle9i


      I met with a little matter in my project.

      When I init the data in my startup-servlet,I can't lookup the datasource.

      Datasource's config should be correct! I'm reffering to 'example/jca/oracle_ds.xml'

      Thus once the web-app has deployed,it is normal for accessing the datasource! I'm worried and indignant.

      Maybe some config was missing or wrong! Help me! thank u very very very much!

      1?config datasource:
      <!--test_oracle_ds.xml-->

      <local-tx-datasource>
      <jndi-name>jdbc/test</jndi-name>
      ....

      ps:config in web.xml and jboss-web.xml
      <!--web.xml-->
      <resource-ref>
      DB Connection
      <res-ref-name>jdbc/test</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      ==============================
      <!--jboss-web.xml-->
      <jboss-web>
      <resource-ref>
      <res-ref-name>jdbc/test</res-ref-name>
      <jndi-name>java:/jdbc/test</jndi-name>
      </resource-ref>
      </jboss-web>


      2?java code

      StartupServlet.java:

      init(..)

      Context init = new javax.naming.InitialContext();
      ctx = (Context) init.lookup("java:comp/env");
      DataSource ds = (DataSource)ctx.lookup("jdbc/test");

      or Context ctx = new javax.naming.InitialContext();
      DataSource ds = (DataSource)ctx.lookup("java:/jdbc/test");

      or Context ctx = new javax.naming.InitialContext();
      DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/test");


      All of this are fail,they give me the info: datasource no bound

      more info ?"javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: jdbc not bound]"
      jdbc not bound: this jdbc must be refer to the "jdbc" of "<jndi-name>jdbc/test</jndi-name>",

      as I have tested "<jndi-name>test</jndi-name>", then give me info- "test not bound".

      The rather that when I read the log,I find the datasource has been bound to "java:/jdbc/test".

      The state of datasource must be valid.
      ........
      mbeans:
      jboss.jca:service=LocalTxCM,name=jdbc/test state: Registered
      jboss.jca:service=ManagedConnectionPool,name=jdbc/test state: Started
      jboss.jca:service=ManagedConnectionFactory,name=jdbc/test state: Started
      .....
      .......
      [org.jboss.web.tomcat.tc5.TomcatDeployer] Linking 'jdbc/test' to JNDI name: java:/jdbc/test


      Thus once the web-app has deployed,it is normal for accessing the datasource! I'm worried and indignant.


      The relative oracle jar(ojdbc14.jar) has been copied into "...server/all/lib".

      I greatly appreciate your timely help.

        • 1. Re: JBOSS,datasource jndi?In the init() mothod of HttpServle
          zhjjava

          help me!

          • 2. Re: JBOSS,datasource jndi?In the init() mothod of HttpServle
            zhjjava

            hahaha,I have solved the problem.

            thank u,genman,but u didn't give me some valuable message.

            We maybe should offer the answer if we knew,so that it can save many people's time!

            I need thank the jboss-wiki,
            http://wiki.jboss.org/wiki/Wiki.jsp?page=DependOnDataSource .

            That gives me the inspiration!

            Thus in your admin-doc,JBoss Admin Development Guide(jboss3.2.6), Figure 3.4,didn't offer the depends element.

            I can find some info in ...docs/dtd/jboss-web_3_2.dtd.
            but when I wrote this message, I found the Figure 9.1----"The complete jboss-web.xml descriptor DTD", ah... ah... ah....

            Reference http://wiki.jboss.org/wiki/Wiki.jsp?page=DependOnDataSource .

            I modified ...sar/...war/WEB-INF/jboss-web.xml,then run jboss,I have looked up the datasource!!!

            <jboss-web> jboss.jca:service=LocalTxCM,name=jdbc/test
            </jboss-web>

            In the log,I can find these info:

            2005-11-08 19:12:49,859 DEBUG [org.jboss.system.ServiceController] waiting in start jboss.web.deployment:war=Crm.war,id=843359960 on jboss.jca:service=LocalTxCM,name=jdbc/test

            ...........

            2005-11-08 19:12:51,046 DEBUG [org.jboss.system.ServiceController] Starting dependent components for: jboss.jca:service=LocalTxCM,name=jdbc/test dependent components: [ObjectName: jboss.web.deployment:war=Crm.war,id=843359960
            state: CREATED
            I Depend On: jboss.jca:service=LocalTxCM,name=jdbc/test

            Depends On Me: ]
            2005-11-08 19:12:51,046 DEBUG [org.jboss.system.ServiceController] starting service jboss.web.deployment:war=Crm.war,id=843359960


            In more detail,I will offer later on. Thank u jboss.Inc!!!

            • 3. Re: JBOSS,datasource jndi?In the init() mothod of HttpServle
              zhjjava

              sorry!
              <jboss-web>
              jboss.jca:service=LocalTxCM,name=jdbc/test
              </jboss-web>

              should be ,maybe use (code /code),:0)

              <jboss-web> <depends>jboss.jca:service=LocalTxCM,name=jdbc/test</depends>
              </jboss-web>


              • 5. Re: JBOSS,datasource jndi?In the init() mothod of HttpServle
                jvorpahl

                I know everyone who posted on this thread is probably long gone (since the thread was dated 2005) but I want to thank you guys for posting this. My company wanted to switch from a standalone Tomcat servlet container to JBoss because of the clustering package and the ability to go beyond 1 GB of memory for the JVM. This post is actually a thank you to the posters and a rant on the piss-poor qualiy of official documents and books that are out there for JBoss.

                I started here 3 weeks ago in a developer/project management position and my large task was to set up 12 machines to run our Production and Staging environments. But the problem is I have exclusively used Web Sphere for the past 5 years, zero JBoss experience. To say the least, I was a bit nervous. I installed JBoss on Monday but the documentation is so rotten for JBoss (even the books written by the JBoss people) that it took me until today to get my JNDI lookups working. My boss thought I was useless, but nowhere did I ever come across a tag mentioned.

                Everywhere they said just create this and that and everything will work. Nowhere did it say "if you can't bind to the DataSource you might want to make sure the DataSource is being deployed before your application is deployed by using the tag."

                The books drill down to such details of other things, but totally skim over the details of initial configuration. They need to go into detail on the complicated things, but also go into detail about problems getting started. I'm sure if I would have read the whole book I would have came across this eventually, but really, when I find a document from HP (http://docs.hp.com/en/5991-5569/index.html) that is more informative and written better than the Official books, there is a problem.

                • 6. Re: JBOSS,datasource jndi?In the init() mothod of HttpServle
                  zhjjava

                  thank you very much