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.
source share