为了账号安全,请及时绑定邮箱和手机立即绑定

Resource不能直接返回吗?

老师,Resource不能直接返回吗,为什么需要new一个新的对象,copy一份

正在回答

3 回答

同问!



0 回复 有任何疑惑可以回复我~

老师,我直接返回Resource报错了,为什么

@RequestMapping("/getResource")

public JsonUtil getResource() {

Resource bean=new Resource();

//BeanUtils.copyProperties(resource, bean);

//System.out.println(resource);

//System.out.println(bean);

return JsonUtil.ok(resource);

}

2018-04-12 13:01:56.862  WARN 10980 --- [nio-8090-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: No serializer found for class org.springframework.context.expression.StandardBeanExpressionResolver 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.context.expression.StandardBeanExpressionResolver and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.imooc.util.JsonUtil["date"]->com.imooc.model.Resource$$EnhancerBySpringCGLIB$$21953e4a["$$beanFactory"]->org.springframework.beans.factory.support.DefaultListableBeanFactory["beanExpressionResolver"])

2018-04-12 13:01:56.862  WARN 10980 --- [nio-8090-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: No serializer found for class org.springframework.context.expression.StandardBeanExpressionResolver 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.context.expression.StandardBeanExpressionResolver and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.imooc.util.JsonUtil["date"]->com.imooc.model.Resource$$EnhancerBySpringCGLIB$$21953e4a["$$beanFactory"]->org.springframework.beans.factory.support.DefaultListableBeanFactory["beanExpressionResolver"])


0 回复 有任何疑惑可以回复我~
#1

開sennsei

应该是加载顺序有关系:https://blog.csdn.net/kane0409/article/details/78865964
2018-06-13 回复 有任何疑惑可以回复我~
#2

zsir94 回复 開sennsei

其实不是加载顺序原因,调试可以发现,返回的json串中,该读取的属性是有值的,但是可以发现data中除了属性文件中的这些字段值,还多了一些属性,如$$beanFactory,原因应该是Resource对象是Spring构造的,Spring给这个对象加入元数据之类的其他属性,这些属性Jackson解析不了,所以报错了,可以看到异常里也提示了 找不到$$beanFactory
2018-07-22 回复 有任何疑惑可以回复我~

当然可以啦

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

Resource不能直接返回吗?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信