Springboot+redis存入key乱码 发表于 2018-11-22 | 分类于 错误集锦 在Spring boot和redis结合的过程中 存入key值会出现乱码 1234//乱码"\xac\xed\x00\x05t\x00\bpassword"//理想"password" 解决方法,添加如下redis配置java,即可解决上述的乱码问题 123456789101112131415161718192021222324252627/** * 解决了springboot结合redis 添加key时产生的\xac\xed\x00\x05t\x00\b乱码 */@Configuration@EnableCachingpublic class RedisConfig { @Bean public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) { RedisTemplate<Object, Object> template = new RedisTemplate<>(); template.setConnectionFactory(connectionFactory); //使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值 Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Object.class); ObjectMapper mapper = new ObjectMapper(); mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); serializer.setObjectMapper(mapper); template.setValueSerializer(serializer); //使用StringRedisSerializer来序列化和反序列化redis的key值 template.setKeySerializer(new StringRedisSerializer()); template.afterPropertiesSet(); return template; }} 赏个🍗吧 打赏 微信支付 支付宝 本文作者: Keeep 本文链接: http://Keeep.coding.me/blog/Springboot-redis存入key乱码/ 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!