Reputation: 606
I've enabled caching in a SpringBoot application with the @EnableCaching and @Cacheable annotations. The cache properties are defined in the application.yaml file.
spring
cache
type=simple
Now I want to know if there is a way to access explicitly the cacheManager bean defined by Spring Boot(created to support the @EnableCaching annotation) without defining a new CacheManager Bean in the configuration files.
I'm basically trying to autowire the cacheManager bean defined by Spring Boot so that I can make explicit calls to it.
@Autowired
private CacheManager cacheManager;
...
Cache cache = cacheManage.getCache("toto")
Regards
Notes: My IDE is telling me that It can't autowire the cacheManager bean
Upvotes: 4
Views: 9359
Reputation: 11
Since I've just stumbled upon this and could see someone else making my mistake. In case you get the error that you cannot autowire CacheManager make sure you are importing the correct one (org.springframework.cache.CacheManager).
Upvotes: 0
Reputation: 606
Finally, the IDE warning was wrong. I was able to autowire the cache manager bean provided by Spring Boot and I was able to call it explicitly.
Regards
Upvotes: 3