小编典典

spring-boot运行状况未显示详细信息(带有详细信息)

spring-boot

我编写了一个实现HealthIndicator的类,该类重写了健康方法。我回来Health.down().withDetail("SupportServiceStatus", "UP").build();

这应该使我的health-endpoint返回:

{
    "status":"UP",
    "applicationHealth": {
        "status":"UP"
    }
}

相反,它只是返回(运行状况,没有详细信息):

{
    "status":"UP",
}

Javacode(有所简化):

@Component
public class ApplicationHealth implements HealthIndicator {

  @Override
  public Health health() {
    return check();
  }

  private Health check() {
    return Health.up().withDetail("SupportServiceStatus", supportServiceStatusCode).build();
  }

}

阅读 289

收藏
2020-05-30

共1个答案

小编典典

根据spring-boot docs:

。。。默认情况下,仅健康状态通过未经身份验证的HTTP连接公开。如果您希望始终获得完整的健康信息,则可以设置endpoints.health.sensitivefalse

解决方案是设置endpoints.health.sensitivefalsein application.properties

application.properties

endpoints.health.sensitive=false

对于> 1.5.1 application.properties

management.security.enabled=false

在Spring Boot 2.0.0.RELEASE(thx @rvit34@nisarg-panchal):

management:
  endpoint:
    health:
      show-details: "ALWAYS"
  endpoints:
    web:
      exposure:
        include: *

management.endpoints.web.exposure.include=* 公开所有端点(如果需要的话)。

当前文档可以在这里找到:https :
//docs.spring.io/spring-boot/docs/current/reference/html/production-ready-
endpoints.html

2020-05-30