RedisTemplate更改JSON序列化
@Configuration public class RedisConfig { @Bean public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) { RedisTemplate<Object, Object> template = new RedisTemplate<>(); template.setConnectionFactory(redisConnectionFactory); //这个设置后没有引号,默认是'xxx',设置后是xxx template.setKeySerializer(StringRedisSerializer.UTF_8); /* 使用Json序列化,默认是JDK序列化 */ template.setDefaultSerializer(RedisSerializer.json()); // // 设置支持事物 // redisTemplate.setEnableTransactionSupport(true); // redisTemplate.afterPropertiesSet(); return template; } }
可以直接设置序列化类型

看源码默认已经实现了一些序列化


浙公网安备 33010602011771号