gpt4 book ai didi

java - Spring Rest 服务调用在第 1 行第 1 列 : Document is empty 返回错误

转载 作者:搜寻专家 更新时间:2023-11-01 00:55:08 25 4
gpt4 key购买 nike

我写了一个 REST 调用,它会在调用时返回健康状态

 @RestController
@RequestMapping(value = "/account")
public class HealthCheckController {

protected final Logger log = LoggerFactory.getLogger(this.getClass());

@RequestMapping(value = "/health", method = RequestMethod.GET, produces = { "application/json" })
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "Returns the health status of the application", notes = "Load balancer user this to confirm the health of the node")
public @ResponseBody String getHealth(HttpServletRequest request, HttpServletResponse response) throws Exception {

log.info("***" + RequestCorrelation.getId() + "***" + "HealthCheckController - getHealth () Called");

return "{\"health\":{\"SERVICES\":\"OK\"}}";
}

}

当我大摇大摆或 postman 打开它时,它会返回正确的响应。但是当我在 chrome 浏览器中点击这个 URL 时,我看到了

This page contains the following errors:

error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.

为什么会这样?以及如何解决这个问题?

最佳答案

同样的问题。拥有一个具有以下类注释和方法的对象:

@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})

@GET
@Path("version")
public String getVersion() { return "v1"; }

将 MediaType.TEXT_PLAIN 添加到 @Produces 注释的末尾。没用。将其移至 @Produces 注释的开头。没用。

将它移动/添加到方法中为我解决了这个问题。您的客户也需要能够接受该媒体类型。

@GET
@Path("version")
@Produces({MediaType.TEXT_PLAIN})
public String getVersion() { return "v1"; )

HTH

关于java - Spring Rest 服务调用在第 1 行第 1 列 : Document is empty 返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36784276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com