Нам нужно включить / отключить кэширование в зависимости от того, настроен ли хост Redis или нет. Я добавил ниже 3 конфига бобов. Это правильный способ отключить? Я все еще вижу ошибку распознавателя кэша после запуска, показанного ниже.
"Не указан CacheResolver и не найден боб типа CacheManager. Зарегистрируйте бин CacheManager или удалите аннотацию @EnableCaching из вашей конфигурации"
Spring Beans
@Bean(destroyMethod="shutdown")
@ConditionalOnProperty(prefix = "spring", name = "redis.host")
public RedissonClient redisson() {
Config config = new Config();
config.useSingleServer()
.setAddress("redis://127.0.0.1:6379");
return Redisson.create(config);
}
@ConditionalOnBean(RedissonClient.class)
@Bean
public RedissonSpringCacheManager cacheManager(RedissonClient redissonClient) {
Map<String, CacheConfig> config = new HashMap<>();
// create "testMap" spring cache with ttl = 24 minutes and maxIdleTime = 12 minutes
config.put("testMap", new CacheConfig(60*60*1000, 12*60*1000));
return new RedissonSpringCacheManager(redissonClient, config);
}
@Bean
@ConditionalOnBean(RedissonSpringCacheManager.class)
@Primary
public CompositeCacheManager compositeCacheManager(RedissonSpringCacheManager cacheManager) {
logger.info("composite cache-manager init...");
CompositeCacheManager compositeCacheManager = new CompositeCacheManager(cacheManager);
compositeCacheManager.setFallbackToNoOpCache(true);
return compositeCacheManager;
}
Спасибо за вашу помощь!