【发布时间】:2019-07-16 15:30:33
【问题描述】:
我使用的是 springboot 2.1.1。 我用@EnableCaching 启用了缓存
一个 CacheManager 被创建并且可以被注入到我的类中。
一旦我添加了一个库https://github.com/MarcGiffing/bucket4j-spring-boot-starter 启动应用程序时出现错误:
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.
at org.springframework.cache.interceptor.CacheAspectSupport.afterSingletonsInstantiated(CacheAspectSupport.java:227)
经过大量调试,我找不到库破坏 CacheManager 的原因和方式。
好像没有使用 CacheAutoConfiguration spring 类:
CacheAutoConfiguration:
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)
Matched:
- @ConditionalOnClass found required class 'org.springframework.cache.CacheManager' (OnClassCondition)
但我在 ProxyCachingConfiguration#L63 中添加了一个断点,并创建了一个 CacheInterceptor (CacheAspectSupport impl) 的实例。 我可以将它注入我的配置类之一。所以bean CacheAspectSupport 似乎存在于应用程序上下文中。
那么为什么 CacheAutoConfiguration 说 bean 丢失了?
谢谢
【问题讨论】: