SpringBoot配置Redis序列化,防止乱码


@Resource
private RedisTemplate<String, Object> redisTemplate;

@Autowired(required = false)
public void setRedisTemplate(RedisTemplate redisTemplate) {
RedisSerializer stringSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(stringSerializer);
redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
redisTemplate.setHashKeySerializer(stringSerializer);
redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
this.redisTemplate = redisTemplate;
}
posted @ 2021-04-25 14:27  金虹巴巴  阅读(252)  评论(0编辑  收藏  举报