我試圖設置有兩個CacheManagers彈簧啓動應用程序,有如下代碼:如何設置兩個不同的CacheManager在春季啓動
@SpringBootApplication
@EnableCaching
public class TestApplication {
...
}
@Configuration
public class TestGuavaCacheConfig extends CachingConfigurerSupport {
...
}
@Configuration
public class TestRedisCacheConfig extends CachingConfigurerSupport {
...
}
但是當我啓動應用程序,它總是失敗與以下錯誤:
Caused by: java.lang.IllegalStateException: 2 implementations of CachingConfigurer were found when only 1 was expected. Refactor the configuration such that CachingConfigurer is implemented only once or not at all. at org.springframework.cache.annotation.AbstractCachingConfiguration.setConfigurers(AbstractCachingConfiguration.java:71) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_66] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_66] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_66] at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_66] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:654) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 59 common frames omitted
似乎春季啓動不能支持兩個CacheManager(s)。這是真的 ?
關於堆棧跟蹤,似乎春季啓動只需要一個實現。不過,我不會看到任何理由同時使用兩種不同的實現。 –