默认情况下,在spring boot中,如果我们点击/actuator/health url,我们就会得到JSON格式的健康信息。但是我将jackson-dataformat-xml用于应用程序中的其他api,这使得健康url将响应格式更改为XML。有没有什么办法可以让spring用JSON来响应健康url?我不想添加我自己的健康url。
这个问题有时会在Spring Boot Actuator /env endpoint returning data as XML - why?之前被问到
但并没有说一个好的解决方案。
发布于 2019-12-19 00:13:24
您可以尝试通过@Primary定义优先于XmlMapper bean的ObjectMapper bean
@Bean
@Primary
public ObjectMapper objectMapper() {
return new ObjectMapper();
}https://stackoverflow.com/questions/59395757
复制相似问题