Configuring a Grails v2.2.4 app with mysql database to use JDBC connection pool and JavaMelody monitor. Everything seems to run properly in GGTS v3.4.0 but unable to deploy a WAR file successfully.
Config.groovy contains:
grails.naming.entries = ['jdbc/myDB': [
type: "javax.sql.DataSource",
factory: "org.apache.tomcat.jdbc.pool.DataSourceFactory",
auth: "Container",
driverClassName: 'com.mysql.jdbc.Driver',
username: <username>,
password: <password>,
url: <database_url>,
<connection pool settings> ] ]
In DataSource.groovy:
dataSource {
jndiName = "java:comp/env/jdbc/myDB"
pooled = true
useUnicode="yes"
characterEncoding="UTF-8"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
dbCreate = 'update' // one of 'create', 'create-drop', 'update', 'validate'
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
Can somebody provide direction on the proper syntax and location of config statement(s) (within the IDE) to bind dataSource to jndi? This app runs on Cloud Foundry so we need to stuff desired Tomcat settings into the war file (i.e., we cannot change Tomcat xml).
SOLUTION:
Move the grails.naming entries block from config.groovy to web-app\META-INF\context.xml
<Resource name="jdbc/myDB" auth="Container" type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
username="[username]" password="[password]" url="[database_url]"
[connection pool settings: property="value" ] />