Ehcache shutdown causing an exception while running test suite

前端 未结 4 933
春和景丽
春和景丽 2021-01-01 16:55

I\'m experiencing the following problem.

I have a test suit in my project and each individual test runs fine.

However when I run them as a suite I some of th

相关标签:
4条回答
  • 2021-01-01 17:33

    JUnit share Spring context for speed. I've avoid from this exception when remove explicitly Spring context closing in one of my test. See Reuse spring application context across junit test classes

    0 讨论(0)
  • 2021-01-01 17:34

    This issue occurs basically, Whenever you Cache shared among multiple applications. So try not to share your cache by setting shared property to false.

    <spring:bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <spring:property name="configLocation" value="classpath:ehcache.xml" /> <spring:property name="shared" value="false" /> </spring:bean>

    But on execution you will encounter

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

    To counter this we need to mention

    <spring:property name="cacheManagerName" value="abc" />

    I hope finally issue will be resolved.

    0 讨论(0)
  • 2021-01-01 17:53

    try to set shared property to false in EhCacheManagerFactoryBean or EhCacheCacheManager in the testing context.

    0 讨论(0)
  • 2021-01-01 17:53

    Make a seperate cache config for tests only! and put scope "prototype"

    @Configuration
    @EnableCaching
    public class EhCacheConfig {
    
     @Bean(name = "cacheManager")
     @Scope("prototype")
     public CacheManager getCacheManager() {
        return new EhCacheCacheManager(getEhCacheFactory().getObject());
     }
    
     @Bean
     @Scope("prototype")
     public EhCacheManagerFactoryBean getEhCacheFactory() {
        EhCacheManagerFactoryBean factoryBean = new EhCacheManagerFactoryBean();
        factoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
        factoryBean.setShared(true);
        return factoryBean;
     }
    }
    
    0 讨论(0)
提交回复
热议问题