I'm using springboot 2.1.1. I enabled cache with @EnableCaching
A CacheManager is created and can be injected in my classes.
Once I add a library https://github.com/MarcGiffing/bucket4j-spring-boot-starter I've got an error when starting the application :
java.lang.IllegalStateException: No CacheResolver specified, and no bean of type CacheManager found. Register a CacheManager bean or remove the @EnableCaching annotation from your configuration.
After a lot of debugging, I can't find why and how the library is breaking the CacheManager.
It seems like the CacheAutoConfiguration spring class is not used :
Did not match:
- @ConditionalOnBean (types: org.springframework.cache.interceptor.CacheAspectSupport; SearchStrategy: all) did not find any beans of type org.springframework.cache.interceptor.CacheAspectSupport (OnBeanCondition)
- @ConditionalOnClass found required class 'org.springframework.cache.CacheManager' (OnClassCondition)
But I added a breakpoint in ProxyCachingConfiguration#L63 and an instance of CacheInterceptor (CacheAspectSupport impl) is created. I can inject it in one of my Configuration class. So the bean CacheAspectSupport seems to exist in the application context.
So why the CacheAutoConfiguration says the bean is missing ?
I found out why.
Configuration class holding the
@EnableCaching annotation was loaded too late when the library was added.
I added a
@AutoConfigureBefore(CacheAutoConfiguration.class) and It is now working.