Springboot+shiro-ehcache 热部署自动重启时报错


Another CacheManager with same name 'es' already exists in the same VM. 


这里报错的意思是在虚拟机上有相同名字的CacheManager ,其中es是ehcache-shiro.xml配置文件ehcache 的名称,

热部署自动重启的时候又重新创建了es,然而虚拟机里面依然存在es,就冲突了。


正确姿势: 

在不存在es对象的时候才重新创建。

@Bean  
    public EhCacheManager ehCacheManager(){  
      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");
          }
      }
      EhCacheManager ehCacheManager = new EhCacheManager();
      ehCacheManager.setCacheManager(cacheManager);
      return ehCacheManager;
    }



你可能感兴趣的:(Spring,Shiro,Spring,Boot)