spring-boot health不显示详细信息(withDetail info)

ola*_*ell 20 java spring spring-boot

我编写了一个实现HealthIndicator的类,重写了health-method.我回来Health.down().withDetail("SupportServiceStatus", "UP").build();

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

{
    "status":"UP",
    "applicationHealth": {
        "status":"UP"
    }
}
Run Code Online (Sandbox Code Playgroud)

相反它只返回(健康,没有细节):

{
    "status":"UP",
}
Run Code Online (Sandbox Code Playgroud)

Javacode(略微简化):

@Component
public class ApplicationHealth implements HealthIndicator {

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

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

}
Run Code Online (Sandbox Code Playgroud)

ola*_*ell 38

根据spring-boot文档:

...默认情况下,仅通过未经身份验证的HTTP连接公开健康状况.如果您对完整的健康信息感到满意,那么您可以将其设置endpoints.health.sensitivefalse.

解决办法是设置endpoints.health.sensitivefalseapplication.properties.

application.properties

endpoints.health.sensitive=false
Run Code Online (Sandbox Code Playgroud)

对于> 1.5.1 application.properties

management.security.enabled=false 
Run Code Online (Sandbox Code Playgroud)

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

management:
  endpoint:
    health:
      show-details: "ALWAYS"
  endpoints:
    web:
      exposure:
        include: *
Run Code Online (Sandbox Code Playgroud)

  • 注意“端点”与“端点”。这让我愣了一分钟。 (2认同)
  • 使用“always”值可以解决这个问题。另一个解决方案是解释如何使用“when-authorized”值,即需要授权哪些安全配置。 (2认同)
  • 快速仅供参考,如果在 yml 中执行,则应该是 ``include: "*"``` (2认同)

rvi*_*t34 11

在Spring Boot 2.0.0.RELEASE:

management:
   endpoint:
      health:
        show-details: "ALWAYS"
Run Code Online (Sandbox Code Playgroud)

  • 通过application.properties:`management.endpoint.health.show-details = ALWAYS` (3认同)

小智 7

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

management:
    security:
        enabled: false
Run Code Online (Sandbox Code Playgroud)


小智 5

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

对于Springboot 2.xxRELEASE,

将以下用于application.properties,

management.endpoint.health.show-details=ALWAYS

在下面用于applicaton.yml,

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