Error:
Cannot resolve constructor'RedisCacheManager(orgspringframeworkdata.reds.core.RedisTemplatesjava.lang.Object,com.demo.webdemo.pojo.User>"
Springboot2.x has changed RedisCacheManager, and the single parameter of RedisCacheManager is no longer applicable.
Therefore, if you want to serialize json objects, please see the following code
@Bean
public CacheManager redisCacheManager(RedisConnectionFactory factory){
Jackson2JsonRedisSerializer<User> user = new Jackson2JsonRedisSerializer<>(User.class);
RedisCacheConfiguration cacheManager =
RedisCacheConfiguration.defaultCacheConfig()
//设置缓存有效时间(1小时)
.entryTtl(Duration.ofHours(1))
//不缓存null结果,若出现null结果时会报异常
.disableCachingNullValues()
//以json形式序列化对象
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(user));
return RedisCacheManager.builder(factory).cacheDefaults(cacheManager).build();
}
This article refers to: springboot 2.2.X custom CacheManager, JSON serialization configuration