Spring 3.2在单元测试期间禁用@Cacheable

时间:2014-01-31 21:44:20

标签: hibernate testng ehcache spring-data-jpa

我的单元测试遇到了问题。我目前使用ehcache和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"/>

但缓存仍在运行!有人有想法吗?

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

Spring配置文件是为此目的而完成的。请参阅文档herehere

在缓存管理器bean(<bean profile="test" ... />)或更高版本中定义配置文件“test”,并使用注释@ActiveProfiles("test")激活或不激活此配置文件。

如果问题仍然存在,请验证定义缓存的上下文是否为根上下文。

相关问题