在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'
看起来已经解决了问题,但现在的问题是,这个“修复”有没有任何副作用?