Spring boot 由于找不到CacheApectSupport,CacheAutomConfiguration不工作
我正在使用springboot 2.1.1。 我使用@EnableCaching启用了缓存 缓存管理器已创建,并可以注入到我的类中 一旦我添加了一个库 启动应用程序时出现错误:Spring boot 由于找不到CacheApectSupport,CacheAutomConfiguration不工作,spring-boot,spring-cache,Spring Boot,Spring Cache,我正在使用springboot 2.1.1。 我使用@EnableCaching启用了缓存 缓存管理器已创建,并可以注入到我的类中 一旦我添加了一个库 启动应用程序时出现错误: java.lang.IllegalStateException: No CacheResolver specified, and no bean of type CacheManager found. Register a CacheManager bean or remove the @EnableCaching an
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的原因和方式
似乎没有使用CacheAutomConfiguration 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实例(CacheApectSupportImpl)。
我可以将它注入到我的一个配置类中。因此,bean CacheAspectSupport似乎存在于应用程序上下文中
那么为什么CacheAutoConfiguration说bean丢失了呢
谢谢,我知道原因了
添加库时,保存@EnableCaching注释的配置类加载得太晚
我添加了一个@AutoConfigureBefore(CacheAutoConfiguration.class),它现在可以工作了。我找到了原因
添加库时,保存@EnableCaching注释的配置类加载得太晚
我添加了一个@AutoConfigureBefore(CacheAutoConfiguration.class),它现在可以工作了