使用Grails 2.5的開箱即用安裝和乾淨的默認配置,添加第二個數據源時總會在嘗試啓動時出現此異常應用程序。這個用來工作在Grails 2.3.x版本沒有問題grails 2.5:使用多個數據源時,「另一個未命名的CacheManager已存在於同一個虛擬機中」
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
}
==== ==== UPDATE
(下hibernate
節DataSource.groovy
)更換這行:
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
有了這一個:
cache.region.factory_class = 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
似乎已經解決了這個問題,但現在的問題是,這個「修復」有什麼缺點嗎?
它應該是 - 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' –