当前位置: 首页 > 知识库问答 >
问题:

Spring执行器/Health对JSON的XML响应

戚俊人
2023-03-14

默认情况下,在spring boot中,如果我们点击/actuator/health url,我们将得到JSON格式的health。但是我在应用程序中使用jackson-dataformat-xml作为我的其他API,这使得健康url将响应格式更改为XML。我们是否可以告诉spring用JSON来响应health url?我不想添加我自己的健康URL。

在Spring Boot Actuator/Env endpoint以XML形式返回数据之前,有时会问这个问题--为什么?

共有1个答案

周和歌
2023-03-14

您可以尝试通过@primary,定义一个ObjectMapperbean,该bean优先于XMLMapperbean:

@Bean
@Primary
public ObjectMapper objectMapper() {
    return new ObjectMapper();
}
 类似资料: