2
votes

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

1
You don't have to autowire cachemanager if you want to use spring cache framework, please check docs.spring.io/spring/docs/current/spring-framework-reference/… - Amit K Bist

1 Answers

2
votes

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