Spring 3.2在单元测试期间禁用@Cacheable [英] Spring 3.2 disable @Cacheable during unit tests
问题描述
我的单元测试遇到问题。我现在使用ehcache whith spring 3.2(@Cacheable)一切正常,但我想在单元测试期间禁用缓存。
因此,在src / test / resources / ehcache.xml我写道: < cache name =myCache
maxElementsInMemory =1
eternal =false
timeToIdleSeconds =0
timeToLiveSeconds =0
overflowToDisk =true
maxElementsOnDisk =0
diskPersistent =false
diskExpiryThreadIntervalSeconds =0
memoryStoreEvictionPolicy =LRU/>
但缓存仍然有效!有人有想法吗?
预先感谢您的帮助! 解决方案
在您的缓存管理器bean(< bean profile =test... />
)中定义一个配置文件test如果你的问题依然存在,那么这个配置文件就会被激活或者激活或者不激活这个配置文件,如果你的问题依然存在的话,那么你可以使用 @ActiveProfiles(test)
。验证定义缓存的上下文是否是根上下文。
I'm facing a problem with my unit tests. I currently use ehcache whith spring 3.2 (@Cacheable) everything works well but i would like to disable the cache during my unit tests.
So in src/test/resources/ehcache.xml i wrote :
<cache name="myCache"
maxElementsInMemory="1"
eternal="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="true"
maxElementsOnDisk="0"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="0"
memoryStoreEvictionPolicy="LRU"/>
but the cache still working ! Is anyone has an idea ?
Thanks in advance for your help!
Spring profile is done for that purpose. See documentation here, here.
Define a profile "test" in your cache manager bean (<bean profile="test" ... />
) or upper and activate or not this profile with annotation @ActiveProfiles("test")
.
If your problem persists, verify that the context which defines the cache is the root context.
这篇关于Spring 3.2在单元测试期间禁用@Cacheable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!