博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关闭spring boot jackson的FAIL_ON_EMPTY_BEANS
阅读量:4041 次
发布时间:2019-05-24

本文共 1771 字,大约阅读时间需要 5 分钟。

发生异常错误信息(redis缓存处理序列化时):

org.springframework.data.redis.serializer.SerializationException: Could not write JSON: No serializer found for class org.springframework.cache.interceptor.SimpleKey and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.springframework.cache.interceptor.SimpleKey and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)

解决办法(定义一个ObjectMapper Bean,jackson2JsonRedisSerializer设置ObjectMapper为自己定义的Bean):

@Beanpublic ObjectMapper objectMapper() {    return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);}/** * Integer redis template redis template. * * @param redisConnectionFactory the redis connection factory * @return the redis template */@Beanpublic RedisTemplate
userStudentRedisTemplate(RedisConnectionFactory redisConnectionFactory) { RedisTemplate
redisTemplate = new RedisTemplate<>(); Jackson2JsonRedisSerializer
jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<> (UserStudentInfo.class); jackson2JsonRedisSerializer.setObjectMapper(objectMapper()); redisTemplate.setConnectionFactory(redisConnectionFactory); redisTemplate.setKeySerializer(jackson2JsonRedisSerializer); redisTemplate.setHashKeySerializer(stringRedisSerializer); redisTemplate.setValueSerializer(jackson2JsonRedisSerializer); redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer); redisTemplate.afterPropertiesSet(); return redisTemplate;}
 

转载地址:http://ieadi.baihongyu.com/

你可能感兴趣的文章
从零实现简易播放器-2.opengl渲染yuv图像
查看>>
Windows下编译可调试的ffmpeg, 包含ffplay
查看>>
意外消息:ppsjy:[MyHookProc]__read web cfg: success ------ :
查看>>
从零实现简易播放器:4.ffmpeg 解码视频为yuv数据-使用avcodec_send_packet与avcodec_receive_frame
查看>>
56个民族的C++ map定义
查看>>
Yotta企业云盘如何实现保护文件安全
查看>>
区块链技术让Yotta企业云盘为行政事业服务助力
查看>>
yotta企业云盘助力制造行业创高峰
查看>>
Yotta企业云盘更好的为媒体广告业服务
查看>>
Yotta企业云盘助力旅游行业新发展
查看>>
Yotta企业云盘助力科技行业创高峰
查看>>
Yotta企业云盘更好地为教育行业服务
查看>>
Yotta企业云盘怎么帮助到能源化工行业
查看>>
企业云盘如何助力商业新发展
查看>>
医疗行业运用企业云盘可以带来什么样的提升
查看>>
教育数字智能化能为现有体系带来新的起点
查看>>
媒体广告业如何将内容资产进行高效地综合管理与利用
查看>>
能源化工要怎么管控核心数据
查看>>
制药医疗使用云盘能带来什么样的好处
查看>>
媒体广告业如何运用云盘提升效率
查看>>