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即可。


相关文章
|
19天前
|
XML 缓存 Java
你尝试过在mybatis某个mapper上同时配置<cache/>和<cache-ref/>吗?
你尝试过在mybatis某个mapper上同时配置<cache/>和<cache-ref/>吗?
46 0
|
存储 缓存 NoSQL
SpringBoot与缓存cache(九)
SpringBoot与缓存cache(九)
100 0
|
缓存 NoSQL Java
基于注解实现缓存的框架 -- SpringCache
Spring Cache是一个框架,实现了基于注解的缓存功能,只需要简单地加一个注解,就能实现缓存功能,大大简化我们在业务中操作缓存的代码。
基于注解实现缓存的框架 -- SpringCache
|
缓存 搜索推荐 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的使用(一)
106 0
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(一)
|
缓存 NoSQL Java
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(三)
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(三)
113 0
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(三)
|
JSON 缓存 数据格式
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(四)
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(四)
132 0
|
canal 缓存 NoSQL
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(五)
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(五)
180 0
|
Java Spring
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(二)
REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(二)
102 0