1

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" ]  />    
LW001
  • 2,452
  • 6
  • 27
  • 36
KnownUnknown
  • 11
  • 1
  • 3
  • If you cannot change Tomcat's config xml's, what's the point of using JNDI instead of the DataSource.groovy? Normally the JNDI is used when you want to let the container configure the connection settings. For Tomcat, this means that you will configure this in his xml's, or maybe I misunderstood your question? –  Mar 13 '14 at 02:16
  • After we configured the JDBC connection pool, JavaMelody could no longer track sql hits. The solution (as I understand it anyway) is to use JNDI and set javamelody.datasources = 'java:comp/env/jdbc/pfinDB'. This works like a champ in the IDE. My hope is that somebody has solved this in grails and can provide guidance. Failing that, it might be helpful to know the solution for Tomcat xml's and try to work back to a grails solution from there. – KnownUnknown Mar 13 '14 at 04:49
  • Joy at last! Was able to resolve by creating context.xml in META-INF folder and defining the there. Able to deploy and run WAR with jdbc pool and fully functional javamelody monitor. Will test some more and clean up as much of the newb-created silliness in my config as possible. – KnownUnknown Mar 13 '14 at 19:43

0 Answers0