shiro加入Ehcache缓存 热部署启动 CacheMana
2018-06-28 本文已影响0人
Morgan7
/**
* 注入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;
}