We have a project that uses spring-boot-cache-starter, registering an ehCache
CacheManager
implementation, and spreading @Cacheables
accross the code.
Then, some other team created an starter, that basically relies on the default configuration autconfigured by spring-boot-cache
starter (hashmap) for its own processing of @Cacheable
methods.
Both codes contain the @EnableCaching
annotation, and our issue is that the behavior is different in case we comment our main project's @EnableCaching annotation.
- If we don't comment
@EnableCaching
in our project, when we use the custom starter, everything works fine.@Cacheables
from the starter are indexed and resolved in the starter scope but@Cacheables
from our domain are resolved in ourehcache
. - If we comment
@EnableCaching
in our project, then both the starter and our project's@Cacheables
are tried to be resolved against ourehCache
implementation.
This breaks a lot of preconceptions I had so far:
I always thought an annotation such as
@Enable
... applied to all the context, regardless of the placement (starter/application configuration), and regardless of whether it was found once or twice when scanning all@Configuration
classes.Why does the case work when both annotations are there, I guess the
CacheManager
in the spring-boot-cache-starter is a@ConditionalOnBean
, so in that case I would expect both projects using theehcache
bean for resolving, not each one's domain
P.S: the @EnableCaching
found in our main project is placed on an inner static @Configuration class. Could this be significant?