Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate Spring 3.2在单元测试期间禁用@Cacheable_Hibernate_Testng_Ehcache_Spring Data Jpa - Fatal编程技术网

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

Hibernate Spring 3.2在单元测试期间禁用@Cacheable,hibernate,testng,ehcache,spring-data-jpa,Hibernate,Testng,Ehcache,Spring Data Jpa,我的单元测试面临一个问题。我目前使用的ehcache带有Spring3.2(@Cacheable),一切正常,但我想在单元测试期间禁用缓存 所以我在src/test/resources/ehcache.xml中写道: <cache name="myCache" maxElementsInMemory="1" eternal="false" timeToIdleSeconds="0" timeToLiveSeconds="0"

我的单元测试面临一个问题。我目前使用的ehcache带有Spring3.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(
)或更高版本中定义配置文件“test”,并使用注释
@ActiveProfiles(“test”)
激活或不激活此配置文件


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

您可以尝试作为一个选项从辅助缓存中退出。(就在运行单元测试之前)感谢您的回答,但问题是,即使我没有在应用程序ContextTest.xml缓存中声明缓存管理器,我也不知道要禁用缓存的写操作。对不起,我误解了。您能为spring上下文配置文件或类和实体类提供许可证吗?要禁用ehcache,只需添加以下属性/值:
net.sf.ehcache.disabled=true
。您可以使用
System.setProperty(“net.sf.ehcache.disabled”,Boolean.TRUE.toString())在
@BeforeClass
注释方法中的代码中执行此操作很抱歉延迟,添加代码不起作用,因此为了解决问题,我在适当的方法上添加了@cacheexecute。再次感谢你的帮助