net.sf.ehcache.CacheException: Another unnamedCacheManager already exists in the same VM

今天在项目中配置多SessionFactory,抛错
Caused by: net.sf.ehcache.CacheException: Another unnamedCacheManager already exists in the same VM. Please provide uniquenames for each CacheManager in the config or do one offollowing:
1. Use one of the CacheManager.create() static factory methodsto reuse same CacheManager with same name or create one ifnecessary
2. Shutdown the earlier cacheManager before creating new onewith same name.

经查,ehcache在2.5以后,CacheManager使用了Singleton,这样在创建多个CacheManager时就会产生上述错误。

解决方法是在Hibernate的hibernateProperties配置中,加上
<propkey="hibernate.cache.region.factory_class">
    org.hibernate.cache. SingletonEhCacheRegionFa ctory
</prop>

原文:http://blog.sina.com.cn/s/blog_6e0810c701014dmv.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Spring框架中,当我们使用注解或配置文件进行依赖注入时,有时会遇到"No qualifying bean of type"的错误。这个错误通常表示Spring容器无法找到符合要求的bean。 针对你提到的"No qualifying bean of type net.sf.ehcache.Ehcache"错误,可能有以下几种原因和解决方法: 1. 缺少依赖:首先,请确保你的项目中已经添加了Ehcache的相关依赖。可以通过Maven或Gradle等构建工具来添加依赖。例如,在Maven中可以添加以下依赖: ```xml <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> <version>2.10.6</version> </dependency> ``` 2. 配置错误:检查你的配置文件,确保已经正确配置了Ehcache相关的bean。可以使用`<bean>`标签或者注解来配置Ehcache相关的bean。例如,在XML配置文件中可以添加以下配置: ```xml <bean id="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation" value="classpath:ehcache.xml"/> </bean> ``` 3. 包扫描问题:如果你使用了包扫描来自动装配bean,确保Ehcache相关的类所在的包已经包含在扫描范围内。可以在配置类上使用`@ComponentScan`注解指定要扫描的包。 以上是可能导致"No qualifying bean of type net.sf.ehcache.Ehcache"错误的一些常见原因和解决方法。如果以上方法都没有解决问题,可以提供更多的代码和配置信息,以便更好地帮助你解决问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值