users@glassfish.java.net

Re: Spring,Glassfish , JNDI and Datasources

From: <glassfish_at_javadesktop.org>
Date: Wed, 19 Mar 2008 15:16:01 PST

There's a difference between component level datasources and datasources in general in JNDI..

If you need to use the "java:comp/env" naming convention - then you have to make sure you have a resource-ref in your web.xml

<resource-ref>
        <description>The default DS</description>
        <res-ref-name>jdbc/DefaultDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
</resource-ref>

^the above will be accessible via "java:comp/env/jdbc/DefaultDS" in your servlet/spring code.

you will also need a glassfish specific deployment descriptor in WEB-INF called "sun-web.xml"

<?xml version="1.0" encoding="UTF-8" ?>
<sun-web-app>
  <resource-ref>
    <res-ref-name>jdbc/DefaultDS</res-ref-name>
    <jndi-name>jdbc/ActualDSNameInGFAdminTool</jndi-name>
  </resource-ref>
<sun-web-app>

You are basically creating an alias from the Server JNDI -> Component JNDI. Make sure jndi-name is pointing to the real JNDI name as registered in the the glassfish admin tool.

JBOSS requires a similar container specific mapping also - in a file called "jboss-web.xml".
[Message sent by forum member 'gdaswani' (gdaswani)]

http://forums.java.net/jive/thread.jspa?messageID=264901