Ehcache 集成 shiro 后再集成spring cache后出现 CacheManager 冲突???

由于之前通过在shiro中集成 Ehcache 实现 对session 进行缓存,但是在今天在使用Ehcache 集成 spring cache 中遇到了一个问题,出现以下异常信息:

net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:|1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary|2. Shutdown the earlier cacheManager before creating new one with same name.|The source of the existing CacheManager is: InputStreamConfigurationSource [stream=sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream@62319d96]
	at net.sf.ehcache.CacheManager.assertNoCacheManagerExistsWithSameName(CacheManager.java:631)
	at net.sf.ehcache.CacheManager.init(CacheManager.java:395)
	at net.sf.ehcache.CacheManager.(CacheManager.java:355)
	at org.apache.shiro.cache.ehcache.EhCacheManager.ensureCacheManager(EhCacheManager.java:213)
	at org.apache.shiro.cache.ehcache.EhCacheManager.init(EhCacheManager.java:199)
	at org.apache.shiro.spring.LifecycleBeanPostProcessor.postProcessBeforeInitialization(LifecycleBeanPostProcessor.java:89)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)

通过异常信息提示 provide unique names for each CacheManager in the config,找到解决方法:


    
        
        
    

对 cacheManagerName 属性自定义一个唯一的名字即可

你可能感兴趣的:(spring)