RestController 报错No converter for class

Spring Boot项目@RestController,produces 配置错误会导致2种异常

一、Could not find acceptable representation

o.s.w.s.m.support.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]

经过仔细检查,原来是produces = "text/html; charset=utf-8"配置错误,发出请求的类型和controller可接收的类型不匹配

二、另外一种情况No converter for [class 。。。  (WSG:实测可以)

o.s.w.s.m.support.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class com...] with preset Content-Type 'null']

这种情况是方法定义了produces = "text/html; charset=utf-8"属性,导致不能把返回对象转成json字符串,去掉produces 属性即可
 
 
转自:
posted @ 2023-06-01 23:17  信铁寒胜  阅读(3996)  评论(0编辑  收藏  举报