2 Replies Latest reply on Dec 8, 2004 11:02 PM by chuckh

    jndi/datasource error similar to jndi/ejb post by codemyth

    chuckh

      Hi

      I am new to jboss and and looking through the posts to find my problem with JNDI which looks very similar to the one that codemyth has. Mine though is with a simple data source using jboss 3.2.6. Codemyth's problem was related to jndi-ejb lookups.

      Here is my source:

      part of web.x.xml where my datasource is defined:

      <resource-ref>
      blah
      <res-ref-name>jdbc/honeypot</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      part of jboss-web.xml where a different resource-ref is defined for jboss (I don't know WHY I need this but I found it on a different forum saying that I would need to define it here - so I did and here it is!):

      <resource-ref>
      <res-ref-name>jdbc/honeypot</res-ref-name>
      <jndi-name>jdbc/honeypot</jndi-name>
      </resource-ref>


      Next is my snippet of code that looks up the resource:

      log.info ("Creating initial context");
      props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      props.put(Context.PROVIDER_URL, "jnp://localhost:1099");

      initCtx = new InitialContext(props);

      listContext (initCtx);
      log.info ("Getting honeypot datasource!");

      dataSource = (DataSource)initCtx.lookup ("java:comp/env/jdbc/honeypot");

      log.info ("Getting Connection!");

      Now part of the exception trace that I am getting:
      2004-12-08 16:04:38,221 INFO [STDOUT] javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: jdbc not bound]
      2004-12-08 16:04:38,231 INFO [STDOUT] at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:972)
      2004-12-08 16:04:38,231 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:615)
      ...
      ...
      ...

      Now I can print out the JNDI tree under "java:comp/env/jdbc" and I do see the "honeypot" entry. But when I look it up this is where I get the exception.

        • 1. Re: jndi/datasource error similar to jndi/ejb post by codemy
          raist_majere

          The resource you define in web.xml is only defined inside your application (it's a logical name), so you must map it to a phisical name using jboss-web.xml. This is to explain why you have to use the jboss-web.xml file.

          If you get this error I think it's due to you haven't defined a datasource with the name jdbc/honeypot in the configuration files of JBoss.

          • 2. Re: jndi/datasource error similar to jndi/ejb post by codemy
            chuckh

            Thanks, but I already figured it out. Turns out that I didn't have the data source file in my deploy directory.

            I must admit that it took 10+ hours to figure it out by digging through google and hacking around with jboss. The jboss docs don't provide enough detail.

            All of the tutorials and descriptions that I found on google didn't explain this. Other sources *abstracted* this detail away.