【发布时间】:2015-10-10 01:13:18
【问题描述】:
使用开箱即用的 Grails 2.5 安装和干净的默认配置,添加第二个数据源在尝试启动应用程序时总是会出现此异常。这在 grails 2.3.x 上运行没有问题
DataSource.groovy:
environments {
development {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://127.0.0.1:3306/myapp"
username = "myuser"
password = "mypass"
}
dataSource_report {
url = "jdbc:mysql://127.0.0.1:3306/myapp_reporting"
username = "someuser"
password = "somepass"
}
}
两个数据库都存在,只要定义一个数据源就可以连接。
在BuildConfig.groovy 中,是所有默认的东西(我假设),包括:
plugins {
build ":tomcat:7.0.55"
compile ":scaffolding:2.1.2"
compile ':cache:1.1.8'
compile ":asset-pipeline:2.1.1"
compile ":spring-security-core:2.0-RC4"
compile ":quartz:1.0.2"
runtime ":hibernate4:4.3.8.1" // or ":hibernate:3.6.10.18"
runtime ":database-migration:1.4.0"
runtime ":cors:1.1.6"
}
这个错误的帖子很多,但似乎是因为作者试图使用非标准版本或缓存。
还尝试将其添加到 Config.groovy,根据这篇文章:https://github.com/grails/grails-core/releases/tag/v2.5.0
beans {
cacheManager {
shared = true
}
}
不幸的是,这没有帮助。
注意,我们使用的是开箱即用的默认配置缓存
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
singleSession = true // configure OSIV singleSession mode
flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}
==== 更新 ====
替换这一行(在DataSource.groovy 下的hibernate 部分):
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
有了这个:
cache.region.factory_class = 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
似乎已经解决了这个问题,但现在的问题是,这个“修复”有什么缺点吗?
【问题讨论】:
标签: grails datasource ehcache