/**
* 注入Ehcache缓存.
*/
@Bean
public EhCacheManager ehCacheManager(){
EhCacheManager ehCacheManager = new EhCacheManager();
ehCacheManager.setCacheManager(ehCacheManagerFactoryBean());
return ehCacheManager;
}
/**
* 管理缓存 解决热部署 Ehcache重复创建CacheManager问题
* @return
*/
@Bean(name = "ehcacheManager")
public CacheManager ehCacheManagerFactoryBean() {
CacheManager cacheManager = CacheManager.getCacheManager("es");
if(cacheManager == null){
try {
cacheManager = CacheManager.create(ResourceUtils.getInputStreamForPath("classpath:config/ehcache-shiro.xml"));
} catch (IOException e) {
throw new RuntimeException("initialize cacheManager failed");
}
}
return cacheManager;
}
网友评论