I can't get my JNDI datasource running. Followed the official grails doc I set up a datasouce in Config.groovy:
grails.naming.entries = [
"mydatasource": [
type: "javax.sql.DataSource",
auth: "Container",
description: "Development Datasource",
url: "jdbc:oracle:oci:@mydb",
username: "user",
password: "pass",
maxActive: "8",
maxIdle: "4"
]
]
So, my DataSource.groovy looks like:
pooled = false
jndiName = "mydatasource"
I tried for "mydatasource" several different notations like "jdbc/mydatasource" or "java:comp/env/jdbc/mydatasource".
With every configuration I receive this: "javax.naming.NameNotFoundException: Name ... is not bound in this Context".
Also when I set up a global resource in the server.xml of my tomcat 6, the deployed grails-war cannot find the JNDI resource.
Any ideas to get this stuff working?
Thx
Edit:
It works fine! Tomcat (version 6 in my case) adds automatically the prefix "java:comp/env" to your datasource jndi-name. So does the tomcat plugin in grails.
Grails Config.groovy (in my case for development environment):
grails.naming.entries = [
"jdbc/mydb": [
type: "javax.sql.DataSource",
auth: "Container",
description: "Development Datasource",
driverClassName: "oracle.jdbc.driver.OracleDriver",
url: "jdbc:oracle:oci:@mydb",
username: "user",
password: "pass",
maxActive: "8",
maxIdle: "4"
]
]
In context.xml (in my case for production environment):
<Resource name="jdbc/mydb" auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:oci:@mydb"
username="user" password="pass" maxActive="50" maxIdle="10"
maxWait="5000"/>
In DataSource.groovy
pooled = false
jndiName = "java:comp/env/jdbc/mydb"
Edit:
A weird thing if you use the datasource as a global resource. The configuration which works for me:
In server.xml:
<Resource name="java:comp/env/jdbc/mydb" auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:oci:@mydb"
username="user" password="pass" maxActive="50" maxIdle="10"
maxWait="5000"/>
In context.xml
<ResourceLink name="jdbc/mydb"
global="java:comp/env/jdbc/mydb"
type="javax.sql.DataSource" />
In DataSource.groovy:
pooled = false
jndiName = "java:comp/env/jdbc/mydb"