Spring Boot Cache - Cannot Get the value

Here is my application yaml file
exchange-api:
  cache-name: exchanges
  cache-ttl: 10000 # 10 seconds

Here is the method
    @CacheEvict(allEntries = true, cacheNames = "${exchange-api.cache-name}")
    @PostConstruct
    @Scheduled(fixedRateString = "${exchange-api.cache-ttl}")
    public void clearCache() {
        logger.info("Caches are cleared");
    }

Here is the error
java.lang.IllegalArgumentException: Cannot find cache named '${exchange-api.cache-name}' for Builder[public void com.example.demo.controller.Controller.clearCache()] caches=[${exchange-api.cache-name}] | key='' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='',true,false


How can I fix it as I get the value as ${exchange-api.cache-name} from application.yaml file? I hope you can help me?
Was this page helpful?