【问题标题】:CacheAutoConfiguration is not working due to CacheAspectSupport not found由于找不到 CacheAspectSupport,CacheAutoConfiguration 不起作用
【发布时间】: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 丢失了?

谢谢

【问题讨论】:

    标签: spring-boot spring-cache


    【解决方案1】:

    我找到了原因。

    在添加库时,我的带有 @EnableCaching 注释的配置类加载得太晚了。

    我添加了一个@AutoConfigureBefore(CacheAutoConfiguration.class),它现在可以工作了。

    【讨论】:

      猜你喜欢
      • 2019-01-20
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-21
      • 2020-06-06
      • 2018-10-20
      • 1970-01-01
      相关资源
      最近更新 更多