grails 2.5:“另一个未命名的CacheManager已经存在于同一个VM中”当使用多个数据源时 [英] grails 2.5: "Another unnamed CacheManager already exists in the same VM" when using multiple datasources

查看:140
本文介绍了grails 2.5:“另一个未命名的CacheManager已经存在于同一个VM中”当使用多个数据源时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


$ b

这两个数据库都存在,只要定义了一个数据源就可以连接到数据源。



<在 BuildConfig.groovy 中,所有的东西都是默认的(我假设),包括:

<$
编译:
编译:缓存:1.1.8'
compile':asset-pipeline:2.1.1
compile:spring-security-core:2.0-RC 4
compile:quartz:1.0.2

runtime:hibernate4:4.3.8.1//或: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 //配置OSIV singleSession模式
flush.mode ='manual'//在事务上下文之外的OSIV会话刷新模式

code $

$ b

==== UPDATE ====



替换这一行(在 DataSource.groovy > hibernate section下) ):

  cache.region.factory_class ='org.hibernate.cache.ehcache.EhCacheRegionFactory'

  


cache.region.factory_class ='org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'

似乎已经修复这个问题,但现在的问题是,这个修复有什么缺点吗?

解决方案

OP已经回答了问题本身):

更改 cache.re gion.factory_class DataSource.groovy 中是这样的:

  hibernate {
cache.region.factory_class =org.hibernate.cache.SingletonEhCacheRegionFactory
}

对于那些出现如下错误的人: net.sf.ehcache.CacheException:另一个未命名的CacheManager已存在于同一个VM中。 ,将以下内容添加到 Config.groovy

  beans {
cacheManager {
shared = true
}
}

请参阅 hibernate插件中ehcache版本的变化


With an out of the box installation of Grails 2.5 and a clean default, config, adding a second datasource always gives this exception when trying to start the app. This used to work no problem with 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"
    }
}

Both databases exist, and can be connected to if only one datasource defined.

In the BuildConfig.groovy, is all the stuff which came as default (I assume), including:

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"
}

There are many posts with this error, but they seem to be because the author is attempting to use non standard versions or caching.

Also tried adding this to Config.groovy, as per this post: https://github.com/grails/grails-core/releases/tag/v2.5.0

beans {
    cacheManager {
        shared = true
    }
}

This did not help, unfortunately.

Note, we are using the default out of the box configured caching

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 ====

Replacing this line (in DataSource.groovy under hibernate section):

cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' 

With this one:

cache.region.factory_class = 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'

Seems to have fixed the issue, but the question now is, are there any downsides to this "fix"?

解决方案

Just to keep track (like the OP has already answered in the question itself):

Change the cache.region.factory_class in DataSource.groovy to like this:

hibernate {
    cache.region.factory_class = "org.hibernate.cache.SingletonEhCacheRegionFactory"
}

And for those who are getting error like: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM., add following to your Config.groovy

beans {
   cacheManager {
      shared = true
  }
}

See Changes in ehcache version in hibernate plugins

这篇关于grails 2.5:“另一个未命名的CacheManager已经存在于同一个VM中”当使用多个数据源时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆