问题记录:
前端说后台抛出了一个500异常,具体提示的是IO 异常, 什么玩意, 有点蒙圈。
后经过排查发现是 jackson 下面 JsonMappingException 这个 类继承了 IoException, 系统中切换 并未打印出异常的详细信息,导致没有及时的发现问题的根源所在。
打印出详细信息后发现:
No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.data.domain.PageImpl["content"]->java.util.Collections$UnmodifiableRandomAccessList[0]->com.hdsxtech.rcyh.entity.YhjhYdjhb["ydjhzb"]->com.hdsxtech.rcyh.entity.YhjhYdjhzb_$$_jvstbff_a["handler"])
给人第一印象就是 里面有嵌套的对象 , 循环序列化了,
使用 @JsonIgorn 属性 添加到不需要序列化的 属性上, 结果又报了一个错
Caused by: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.data.domain.PageImpl["content"]->java.util.Collections$UnmodifiableRandomAccessList[0]->com.hdsxtech.rcyh.entity.YhjhYdjhb["ydjhzb"]->com.hdsxtech.rcyh.entity.YhjhYdjhzb_$$_jvstf80_a["handler"])
百度了一下, 简单说由hibernate 懒加载引起
@ManyToOne(fetch=FetchType.EAGER,cascade=CascadeType.REFRESH)
@JoinColumn(name = "jhzbid")
private YhjhYdjhzb ydjhzb;
将fetch 属性 有Lazy 改为Eager , 问题暂时的得到解决