【问题标题】:spring-boot health not showing details (withDetail info)spring-boot 健康未显示详细信息(withDetail info)
【发布时间】:2015-10-06 13:25:12
【问题描述】:

我编写了一个实现 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();
  }

}

【问题讨论】:

    标签: java spring spring-boot


    【解决方案1】:

    根据 spring-boot 文档:

    。 . .默认情况下,只有健康状态通过未经身份验证的 HTTP 连接公开。如果您愿意始终公开完整的健康信息,您可以将endpoints.health.sensitive 设置为false

    解决方法是在application.properties中设置endpoints.health.sensitivefalse

    application.properties

    endpoints.health.sensitive=false
    

    对于 >1.5.1 application.properties

    management.security.enabled=false 
    

    在 Spring Boot 2.0.0.RELEASE(感谢 @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

    【讨论】:

    • 对于 > 1.4.1 我认为。需要 1.4.2-RELEASE 中的管理标志
    • 我可以看到 management.security.enabled 出现在文档中的 1.3.1 中。如果更多人有确切的信息,它将被应用。 docs.spring.io/spring-boot/docs/${version}/reference/html/production-ready-monitoring.html
    • 请注意 endpointendpoints。这让我愣了一分钟。
    • 使用always 值可以解决这个问题。另一种解决方案是解释如何使用when-authorized 值,即需要授权哪个安全配置。
    • 快速仅供参考,如果在 yml 中进行,则应该是 include: "*"
    【解决方案2】:

    在 Spring Boot 2.0.0.RELEASE:

    management:
       endpoint:
          health:
            show-details: "ALWAYS"
    

    【讨论】:

    • 通过 application.properties:management.endpoint.health.show-details=ALWAYS
    • 哦,是的,谢谢!我很困惑,这在文档中隐藏得如此之好。获得“DOWN”状态并且不知道为什么会这样是很烦人的。
    • 我在 yml 中使用 Spring 2.1.3 版本及以下属性解决了我的问题:端点:健康:敏感:错误关闭:启用:真实管理:端点:网络:曝光:包括:“*”端点:健康:显示详细信息:“总是”
    【解决方案3】:

    感谢@rvit34 和@Ninja Code Monkey 的工作。

    对于 Springboot 2.x.x.RELEASE,

    在下面使用 application.properties,

    management.endpoint.health.show-details=ALWAYS

    在下面使用 applicaton.yml,

    management: endpoint: health: show-details: "ALWAYS"

    【讨论】:

      【解决方案4】:

      设置 'endpoints.health.sensitive' 没有任何区别...必须设置:

      management:
          security:
              enabled: false
      

      【讨论】:

      • 我认为这只是因为介于 1.4.1.RELEASE 和 1.5.1.RELEASE 之间的某个时间(我刚刚升级并且必须这样做)
      【解决方案5】:

      需要补充

      management.endpoint.health.show-details=always
      

      到 Application.properties

      【讨论】:

        【解决方案6】:

        对于 Spring boot 2.X,我的 application.properties 文件中有以下详细信息:

        management.endpoints.web.exposure.include=*
        management.endpoint.health.show-details=ALWAYS
        

        【讨论】:

          【解决方案7】:

          我遇到了同样的问题,在 Spring Boot 1.5.9 版本上我必须设置

          management.security.enabled=false
          

          【讨论】:

            猜你喜欢
            • 2021-11-06
            • 2019-11-12
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-07-27
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多