[jboss-user] [JNDI/Naming/Network] - [JBoss 4.0.2] NameNotFoundException: datasource not bound

rufik do-not-reply at jboss.com
Fri Mar 21 06:08:39 EDT 2008

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???

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4138258#4138258

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4138258

More information about the jboss-user mailing list