使用mysql数据库配置Grails v2.2.4应用程序以使用JDBC连接池和JavaMelody监视器。一切似乎都在GGTS v3.4.0中正常运行,但无法成功部署WAR文件。
Config.groovy包含:
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> ] ]
在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'
}
有人可以提供有关config语句(在IDE中)的正确语法和位置的指示,以将dataSource绑定到jndi吗?这个应用程序在Cloud Foundry上运行,因此我们需要将所需的Tomcat设置填充到war文件中(即,我们无法更改Tomcat xml)。
解决方案:
将grails.naming条目块从config.groovy移动到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" ] />