Spring 3.2 disable @Cacheable during unit tests

这一生的挚爱 提交于 2019-12-11 19:13:20

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/21490617/spring-3-2-disable-cacheable-during-unit-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!