Spring boot cache. No cache could be solved for Builder

According to the simplest configuration of using the cache when loading spring, the CacheManager is used (in this class the cache map will be initialized):

@Configuration @EnableCaching public class CacheService extends CachingConfigurerSupport { @Bean public CacheManager concurrentMapCacheManager() { ConcurrentMapCacheManager cmcm = new ConcurrentMapCacheManager(); return cmcm; } @Bean @Primary public CacheManager guavaCacheManager() { GuavaCacheManager gcm = new GuavaCacheManager(); return gcm; } } 

and serviceImpl.java :

  @Cacheable(cacheManager="guavaCacheManager") @Override public List<RoleVO> getDataForCreateNewOperator() { ... } 

But he throws:

 java.lang.IllegalStateException: No cache could be resolved for 'Builder[public java.util.List getDataForCreateNewOperator()] caches=[] | key='' | keyGenerator='' | cacheManager='guavaCacheManager' | cacheResolver='' | condition='' | unless='' | sync='false'' using resolver ' org.springframework.cache.interceptor.SimpleCacheResolver@38466d 10'. At least one cache should be provided per cache operation. 

EDIT: if I assign cacheName to cacheManager and use it in the recommended method, the exception will disappear. But all methods in the bean will be cached, and only one @Cacheable method.

+5
source share
1 answer

I am using Ehcache and I had the same problem because I had two different names for cache and Cacheable.

 Please make you use same name for cache and Cacheable. @Cacheable("codetable") <cache name="codetable" maxEntriesLocalHeap="100" maxEntriesLocalDisk="1000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" memoryStoreEvictionPolicy="LFU" transactionalMode="off"> <persistence strategy="localTempSwap" /> </cache> 
+1
source

Source: https://habr.com/ru/post/1270050/


All Articles