stepio / coffee-boots

Support property-based configuring of multiple Caffeine caches for Spring Cache abstraction.
Apache License 2.0
30 stars 7 forks source link

java.lang.IllegalStateException: No CacheResolver specified, and no bean of type CacheManager found. Register a CacheManager bean or remove the @EnableCaching annotation from your configuration. #138

Open Blackbaud-JasonBodnar opened 2 years ago

Blackbaud-JasonBodnar commented 2 years ago

I have @EnableCaching on my application class.

In application.properties I have:

# caching
coffee-boots.cache.spec.reCountries=expireAfterWrite=3d,expireAfterAccess=1d,maximumSize=500
coffee-boots.cache.spec.reInstalledCountries=expireAfterWrite=3d,expiresAfterAccess=1d,maximumSize=500

But when I try to run a test or boot my application I get:

java.lang.IllegalStateException: No CacheResolver specified, and no bean of type CacheManager found. Register a CacheManager bean or remove the @EnableCaching annotation from your configuration.

If I add a bean with a CacheManager:

@Bean
public CacheManager cacheManager() {
    return new MultiConfigurationCacheManager();
}

My application runs but it doesn't look like my cache is configured per the .properties file:

@Autowired
CacheManager cacheManager
...
cacheManager.getCache("reCountries")

gives me:

result = {org.springframework.cache.caffeine.CaffeineCache@20802} 
 allowNullValues = true
 cache = {com.github.benmanes.caffeine.cache.UnboundedLocalCache$UnboundedLocalManualCache@20804} 
  cache = {com.github.benmanes.caffeine.cache.UnboundedLocalCache@20807}  size = 1
  policy = null
 name = "reCountries"

Do I need to provide a CacheManager bean or does coffee-boots do that for me already? If it does, what am I doing wrong that causes the error I'm getting?

stepio commented 2 years ago

Hello @Blackbaud-JasonBodnar !

Sorry that you have this problem. Which versions of Spring & Spring Boot do you use?

Blackbaud-JasonBodnar commented 2 years ago

Spring 5.3.20 Spring Boot 2.6.7