Spring Boot Actuator/env 端点以 XML 形式返回数据 - 为什么? [英] Spring Boot Actuator /env endpoint returning data as XML - why?

查看:24
本文介绍了Spring Boot Actuator/env 端点以 XML 形式返回数据 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有几个作为微服务运行的 Spring Boot 应用程序.它们中的每一个都运行 spring boot 执行器,以允许我们监视/metrics、/env、/health 等.在这些服务中的一个上,/env 端点在浏览器中请求时以 XML 形式返回数据.此外,XML 是无效的,但我真正关心的是让端点以 json 形式返回数据.XML 无效的原因是因为我们使用的是 Spring Cloud Config,并且第一个元素包含 GitHub URL,这使其无效.

We have several Spring Boot apps running as microservices. Each of them are running spring boot actuator to allow us to monitor /metrics, /env, /health, etc. On just one of these services the /env endpoint is returning data as XML when requested in the browser. Further, the XML is invalid, but what I really care about is getting the endpoint to return data in json. The reason the XML is invalid is because we are using Spring Cloud Config and the first element contains the GitHub URL which makes it invalid.

<LinkedHashMap xmlns=""><profiles>development</profiles><configService:https://github.com/ourcompany/configs/usage.yml>

我找不到关于这个项目的任何不同之处,它允许以 json 形式返回数据.

I can not find anything different about this one project that would allow the data to be returned in json.

如果我使用 cURL 并传递值 = application/json 的 Accept 标头,服务将正确返回 json,但为什么浏览器返回 XML?我还注意到这个服务是我可以传递 Accept = application/xml 并让它返回 XML,但我的其他服务在请求 XML 时返回 406 Not Acceptable 响应.奇怪.

If I use cURL and pass an Accept header with value = application/json the service will correctly return json, but why is the browser returning XML? What I also noticed with this service is that I can pass Accept = application/xml and get it to return XML, but my other services return a 406 Not Acceptable response when requesting XML. Strange.

我们正在使用 spring-boot-starter-parent 版本 1.2.2.RELEASE 以及 spring-cloud-starter 1.0.0.RELEASE.

We are using spring-boot-starter-parent version 1.2.2.RELEASE as well as using spring-cloud-starter 1.0.0.RELEASE.

推荐答案

ci_ 上面的评论是正在发生的事情.拥有 XmlMapper 会导致执行器端点返回 XML.点击/env.json 端点将为我解决问题.

ci_'s comment above is what is happening. Having an XmlMapper caused the actuator endpoints to return XML. Hitting the /env.json endpoint will solve the issue for me.

这篇关于Spring Boot Actuator/env 端点以 XML 形式返回数据 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆