我正在将我的应用程序从spring Boot 1.5.x迁移到2.0.x。我想保留jedis,但是我在示例化RedisCacheManager
时遇到了问题。
现在构造函数签名是
RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration)
但之前是:
RedisCacheManager(RedisOperations redisOperations)
我定义了这个bean,在作用域中只有RedisTemplate
:
@Bean
public RedisCacheManager redisCacheManager(RedisTemplate redisTemplate) {
HandleRedisCacheManager redisCacheManager = new HandleRedisCacheManager(redisTemplate);
redisCacheManager.setUsePrefix(true);
return redisCacheManager;
}
现在应该如何创建?
3条答案
按热度按时间ecfdbz9o1#
尝试以下代码,它适用于我的spring-boot 2.1.0.RELEASE
vuktfyat2#
它不再接受RedisTemplate。所以试试这个:
qv7cva1a3#
@Bean public CacheManager cacheManager(){ RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig().disableCachingNullValues().entryTtl(Duration.ofHours(1)).serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(RedisSerializer.json()));. println();return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(jedisConnectionFactory()).cacheDefaults(redisCacheConfiguration).build();}