Another unnamed CacheManager already exists in the same VM (ehCache 2.5) 解决办法

简介: Another unnamed CacheManager already exists in the same VM (ehCache 2.5) 解决办法

vm中存在2个CacheManager导致报错,百度了一下,大部分都是建议换成2.4的版本来解决问题,因为2.5以后不允许vm中存在2个实例。但是我就是非要用2.5那,该怎么办? 因为我要在自己的业务逻辑中操作CacheManager,我的配置文件代码如下:

<cache:annotation-driven/>
    <bean id="cacheManager"
          class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache" />
    <bean id="ehcache"
          class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:config-location="classpath:ehcache.xml" />
<mapper namespace="com.raymon.cloudq.dao.WindowCurrentStateMapper" >
    <cache type="org.mybatis.caches.ehcache.EhcacheCache"
            eviction="FIFO"
            flushInterval="60000"
            size="512"
            readOnly="true"/>


mybatis配置缓存,查看源码后,发现会重新创建一个CacheManager。如下:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package org.mybatis.caches.ehcache;
import java.util.concurrent.locks.ReadWriteLock;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import org.apache.ibatis.cache.Cache;
public abstract class AbstractEhcacheCache implements Cache {
    protected static CacheManager CACHE_MANAGER = CacheManager.create();

终于在stackoverflow找到答案,只需要配置

<bean id="cacheManager"
      class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
      p:shared="true"/>
EhCa

cheManagerFactoryBean p:shared设置为true即可。


相关文章
|
5月前
|
XML 缓存 Java
你尝试过在mybatis某个mapper上同时配置<cache/>和<cache-ref/>吗?
你尝试过在mybatis某个mapper上同时配置<cache/>和<cache-ref/>吗?
46 0
|
10月前
|
SQL
MyBaits异常解决:There is no getter for property named ‘ID‘ in ‘class ***‘
MyBaits异常解决:There is no getter for property named ‘ID‘ in ‘class ***‘
|
SQL XML 存储
Data Access 之 MyBatis(五)- MyBatis Cache(下)
Data Access 之 MyBatis(五)- MyBatis Cache
Data Access 之 MyBatis(五)- MyBatis Cache(下)
|
SQL 缓存 Java
Data Access 之 MyBatis(五)- MyBatis Cache(上)
Data Access 之 MyBatis(五)- MyBatis Cache
Data Access 之 MyBatis(五)- MyBatis Cache(上)
|
缓存 搜索推荐 Java
玩转Spring Cache --- @Cacheable使用在MyBatis的Mapper接口上(解决Null key returned for cache operation)【享学Spring】(下)
玩转Spring Cache --- @Cacheable使用在MyBatis的Mapper接口上(解决Null key returned for cache operation)【享学Spring】(下)
玩转Spring Cache --- @Cacheable使用在MyBatis的Mapper接口上(解决Null key returned for cache operation)【享学Spring】(下)
|
XML SQL 缓存
玩转Spring Cache --- @Cacheable使用在MyBatis的Mapper接口上(解决Null key returned for cache operation)【享学Spring】(上)
玩转Spring Cache --- @Cacheable使用在MyBatis的Mapper接口上(解决Null key returned for cache operation)【享学Spring】(上)
|
Java Spring
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(二)
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(二)
100 0
|
JSON 缓存 数据格式
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(四)
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(四)
130 0
|
canal 缓存 NoSQL
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(五)
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(五)
175 0