当apache shiro跟spring cache结合使用时
如果双方都用ehcache作为缓冲库的话,对于cachemanger的设定会产生冲突,因为如果没有给shiro的EhCacheManager设定cachemanager的话,会创建一个默认名称的cachemanager,而spring的cache自动配置也同样会创建一个默认名称的cachemanager,由于ehcache2.5以后,不允许同一个jvm上存在两个同样名字的cachemanager,所以会报错。
解决的方法有两个,一个是自定义配置java文件,把名称改为另外一个,或者干脆就用同一个cachemanager。
下面是用同一个cachemanager时的配置方法。
@Bean(name = "ehcache") public EhCacheManagerFactoryBean ehCacheManagerFactoryBean(){ EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean(); ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml")); ehCacheManagerFactoryBean.setShared(true); return ehCacheManagerFactoryBean; } @Bean(name = "cacheManager") public EhCacheCacheManager ehCacheCacheManager(){ EhCacheCacheManager ehCacheCacheManager = new EhCacheCacheManager(); ehCacheCacheManager.setCacheManager(ehCacheManagerFactoryBean().getObject()); return ehCacheCacheManager; } @Bean(name = "ehCacheManager") @DependsOn("lifecycleBeanPostProcessor") public EhCacheManager ehCacheManager(){ EhCacheManager ehCacheManager = new EhCacheManager(); ehCacheManager.setCacheManager(ehCacheManagerFactoryBean().getObject()); return ehCacheManager; }
相关推荐
杜鲁门 2020-11-05
luckyxl0 2020-08-16
Dullonjiang 2020-08-09
xclxcl 2020-08-03
zmzmmf 2020-08-03
MicroBoy 2020-08-02
ganjing 2020-08-02
likesyour 2020-08-01
zmzmmf 2020-07-09
MicroBoy 2020-07-05
zzhao 2020-06-26
子云 2020-06-18
visionzheng 2020-06-07
neweastsun 2020-06-04
ErixHao 2020-06-03
GDreams0 2020-06-01
ganjing 2020-05-29
zmzmmf 2020-05-28
nullcy 2020-05-26