1

使用 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'
}

有人可以提供有关配置语句(在 IDE 内)的正确语法和位置的指导,以将数据源绑定到 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" ]  />    
4

0 回答 0