I’m trying to configure a Grails 1.3.5 app to work with the default tomcat instance built into Grails using JNDI. The app doesn’t use GORM. I want to connect to the datasources myself. I’m using a library for the model layer we use for other apps.
resources.xml
As well as the bean headers I have:
<import resource="data.xml" />
<import resource="service.xml" />
In data.xml I have:
<bean id="subjectJdbcDao"
class="uk.co.xxx.dao.subjects.SubjectJdbcDao">
<property name="dataSource" ref="jobDataSource"/>
</bean>
In resources.groovy I have:
def jobDataSource = new org.springframework.jdbc.datasource.DriverManagerDataSource('oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:@berlin:1521:casdev','cso','job')
grails.naming.entries = ['jdbc/job':jobDataSource]
I’ve tried everything but can’t seem to get the data.xml file to find the jndi data sources. I keep getting this error:
2010-11-22 17:09:38,855 ERROR [context.GrailsContextLoader] Error executing bootstraps: Error
creating bean with name 'SubjectJdbcDao' defined in URL [file:grails-app/conf/spring/data.xml]:
Cannot resolve reference to bean 'jobDataSource' while setting bean property 'dataSource'; nested
exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named
'jobDataSource' is defined
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'SubjectJdbcDao' defined in URL [file:grails-app/conf/spring/data.xml]: Cannot resolve reference to
bean 'jobDataSource' while setting bean property 'dataSource'; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jobDataSource' is
defined
at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)
Does anyone know where I should put my datasource definitions so that they get picked up?
Your datasource should be an instance of a org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.
If you run the tomcat embedded in grails, you will need to simulate your JNDI datasource by adding the following entry in Config.groovy:
If you want to run your application as a war and need an actual JNDI Datasource deployed and managed by tomcat, you need to create a tomcat context for your application:
If your application is jobapp.war, you must put a jobapp.xml under TOMCAT_HOME/conf/Catalina/localhost/jobapp.xml
This jobapp.xml should contain the following:
I believe this should do the trick
(make sure your drivers are available to your tomcat installation if you run it as a war)
Regards,
Vincent Giguère