先来一段前端返回得到的错误:
HTTP Status 406 -
type Status report
message:
description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request “accept” headers.
从前端返回的请求发现Response Headers
里的Content-Type
类型为text/html,显然返回的类型是错误的。因为要返回json
字符串,在@RequestMapping
的produces
指定了返回的类型为application/json;charset=utf-8,所以猜测对象没有被序列化,缺少序列化所需要的jar包。
排查过程:
到项目的External Libraries
中是否有jackson
序列化相关的jar包,果然未发现与jackson
相关的jar包。问题找到了下一步就是往pom.xml
中加入jackson
依赖,依赖如下(没有version是因为继承了父maven的pom.xml):