Ehcache关闭在运行测试套件时导致异常

gen*_*nzo 16 spring ehcache spring-test junit4

我遇到了以下问题.

我的项目中有一套测试服,每个测试都运行良好.

但是,当我将它们作为套件运行时,我们中的一些会因以下异常而失败:

Caused by: java.lang.IllegalStateException: The dao Cache is not alive (STATUS_SHUTDOWN)
    at net.sf.ehcache.Cache$CacheStatus.checkAlive(Cache.java:4269)
    at net.sf.ehcache.Cache.checkStatus(Cache.java:2703)
    at net.sf.ehcache.Cache.get(Cache.java:1576)
    at org.springframework.cache.ehcache.EhCacheCache.get(EhCacheCache.java:61)
    at org.springframework.cache.interceptor.CacheAspectSupport.inspectCacheables(CacheAspectSupport.java:310)
    at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:198)
    at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:66)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
Run Code Online (Sandbox Code Playgroud)

有没有办法避免这种行为,即在多次测试中保持缓存活着还是正确关闭?

Bas*_*hdy 5

尝试在测试上下文中EhCacheManagerFactoryBeanEhCacheCacheManager在测试上下文中将共享属性设置为 false 。

  • 如何在测试上下文中将共享属性设置为 false,是否可以提供一个示例? (2认同)