1 Reply Latest reply on Mar 21, 2008 10:46 AM by R M

    [JBoss 4.0.2] NameNotFoundException: datasource not bound

    R M Newbie

      Hi,
      I have not trivial problem with looking up datasource. Some details:

      xxx-ds.xml datasource entry:

       <local-tx-datasource>
       <jndi-name>jdbc/cms</jndi-name> <connection-url>jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=latin2</connection-url>
       <driver-class>org.gjt.mm.mysql.Driver</driver-class>
       <user-name>user</user-name>
       <password>passwd</password>
       </local-tx-datasource>
      


      web.xml entry:
       <resource-ref>
       <description>CMS Datasource</description>
       <res-ref-name>jdbc/cms</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
       <res-sharing-scope>Shareable</res-sharing-scope>
       </resource-ref>
      


      jboss-web.xml entry:
       <resource-ref>
       <res-ref-name>jdbc/cms</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <jndi-name>java:jdbc/cms</jndi-name>
       </resource-ref>
      


      Code that does lookup:
      InitialContext initctx = new InitialContext();
      initctx.lookup("java:comp/env/jdbc/cms");
      



      This code works in most cases well (within EJB module, web app, etc) but I have problem in one special case: I have servlet (let call it JobInitializerServlet) that uses Quartz to schedule some jobs.
      This servlet uses my class QuartzManager to find all jobs in database and schedule them. Single job is just a single EJB which "have to be loaded" from db with EJB.load() method.
      Load method uses his own DAO class, where is done datasource lookup using code above. So QuartzManager calls EJB and EJB internally calls lookup of DS.

      And there is a problem:
      javax.naming.NameNotFoundException: cms not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:278)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:252)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:252)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:701)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
       at javax.naming.InitialContext.lookup(InitialContext.java:392)
      



      As I can say, I tried to do same DS lookup in JobInitializerServlet before calling QuartzManager and it works! But a while later (in QuartzManager code) looking up DS fails. Why???




        • 1. Re: [JBoss 4.0.2] NameNotFoundException: datasource not boun
          R M Newbie

          Adding some more info about JobInitializerServlet:
          code is within init() method of the servlet (maybe it does matter?), something like that:

          public void init(ServletConfig config) throws ServletException {
           String lookupName = "java:comp/env/jdbc/cms";
           //this code works!
           try {
           InitialContext ctx = new InitialContext();
           ctx.lookup(lookupName);
           } catch (Exception e) {
           log.error("Error looking up " + lookupName, e);
           }
          
           //this code inside manager doesn't work!
           try {
           QuartzManager.addAllJobs();
           } catch (Exception exc) {
           log.error("Error initializing quartz job's manager! ");
           }
          }