Reputation: 35
I have a JCacheCacheManager injected into my application by a spring boot starter. This works fine until i define an ehCacheCacheManager-Bean inside the same app, which is used in the @cacheable-annotation of a single repository method. This itself works as well, but the injected JCacheCacheManager can not be found any more.
Upvotes: 0
Views: 883
Reputation: 35
I did it slightly different: I changed the @Cacheable-Annotations referencing a custom CacheResolver Bean witch uses the EhCache. The EhCache itself is no bean anymore. Conflict solved.
Upvotes: 0
Reputation: 1321
That's an expected behavior in spring boot for almost everything in general. Spring boot provides opinionated beans with provided (or implicit if not provided) configuration. The moment spring boot see any of bean being explicitly provided by user, spring boot will stop auto providing it's opinionated bean. That's the whole purpose of AutoConfiguration.
In order for you to work with both cache managers, use following outline
@Primary
- this bean will be injected by default everywhere as long as @Qualifier
is not used asking for specific bean.@Bean('ehCacheManager')
@Cacheable(cacheManager="ehCacheManager" ...)
Upvotes: 2