Another unnamed CacheManager already exists in the same VM (ehCache 2.5)

前端 未结 17 1965
囚心锁ツ
囚心锁ツ 2020-11-30 20:41

This is what happens when I run my junit tests...

Another CacheManager with same name \'cacheManager\' already exists in the same VM. Please 
provide unique          


        
17条回答
  •  长情又很酷
    2020-11-30 21:21

    Setting the EhCacheManagerFactoryBean#shared to true worked for me.

    Setting the EhCacheManagerFactoryBean#acceptExisting to true DIDN'T work for me.

    import org.springframework.cache.ehcache.EhCacheCacheManager;
    import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.core.io.ClassPathResource;
    
    @Configuration
    public class EhCacheConfiguration {
    
        @Bean
        public EhCacheCacheManager ehCacheCacheManager() {
    
            return new EhCacheCacheManager(ehCacheManagerFactoryBean().getObject());
        }
    
    
        @Bean
        public EhCacheManagerFactoryBean ehCacheManagerFactoryBean() {
    
            EhCacheManagerFactoryBean cacheManagerFactoryBean = new EhCacheManagerFactoryBean();
    
            cacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
            cacheManagerFactoryBean.setShared(true);
    
            return cacheManagerFactoryBean;
        }
    }
    

    As explained in Using EhCache in Spring 4 without XML

提交回复
热议问题