According to link, the simplest configuration to use cache in spring boot is using CacheManager (an cache Map would be initialized in this class):
@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 in serviceImpl.java:
@Cacheable(cacheManager="guavaCacheManager")
@Override
public List<RoleVO> getDataForCreateNewOperator() {
...
}
But it 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@38466d10'. At least one cache should be provided per cache operation.
EDIT:
if I assign a cacheName in cacheManager, and use it in the advised method, the exception is gone. But all methods in the bean would be cached, while I only assigned @Cacheable on one method.