Could not write JSON: could not initialize proxy [com.example.demo.bean.Account#2] - no Session;
问题描述:
Could not write JSON: could not initialize proxy
[com.example.demo.bean.Account#2] - no Session; nested exception is
com.fasterxml.jackson.databind.JsonMappingException: could not
initialize proxy [com.example.demo.bean.Account#2] - no Session
(through reference chain:
com.example.demo.bean.Account H i b e r n a t e P r o x y HibernateProxy HibernateProxyefC7Ku3G[“name”]):
原因分析:
导致这一问题的原因是:json序列化我们的实体类时,我们的实体类还没有成功加载。即懒加载晚于序列化导致。
解决方案:
在实体类这里加上这个注解@Proxy(lazy = false)
再运行,可以了