亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號