java spring-boot 健康未显示详细信息(withDetail info)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32971182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 21:01:38  来源:igfitidea点击:

spring-boot health not showing details (withDetail info)

javaspringspring-boot

提问by olahell

I have written a class implementing HealthIndicator, overriding the health-method. I return Health.down().withDetail("SupportServiceStatus", "UP").build();

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

This should make my health-endpoint return:

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

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

Instead it just returns (health, without details):

相反,它只是返回(健康,没有详细信息):

{
    "status":"UP",
}

Javacode (somewhat simplified):

Java代码(有些简化):

@Component
public class ApplicationHealth implements HealthIndicator {

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

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

}

回答by olahell

According to spring-boot docs:

根据 spring-boot 文档:

. . . by default, only the health status is exposed over an unauthenticated HTTP connection. If you are happy for complete health information to always be exposed you can set endpoints.health.sensitiveto false.

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

Solution is to set endpoints.health.sensitiveto falsein application.properties.

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

application.properties

应用程序属性

endpoints.health.sensitive=false

For >1.5.1 application.properties

对于 >1.5.1 application.properties

management.security.enabled=false 

At Spring Boot 2.0.0.RELEASE (thx @rvit34and @nisarg-panchal):

在 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=*exposes all endpoints, if that is what you want.

management.endpoints.web.exposure.include=*公开所有端点,如果这是你想要的。

Current documentation can be found here: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html

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

回答by rvit34

At Spring Boot 2.0.0.RELEASE:

在 Spring Boot 2.0.0.RELEASE:

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

回答by Ninja Code Monkey

Setting 'endpoints.health.sensitive' made no difference... had to set:

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

management:
    security:
        enabled: false

回答by Rakesh

Thanks @rvit34 and @Ninja Code Monkey its working.

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

For Springboot 2.x.x.RELEASE,

对于 Springboot 2.xxRELEASE,

Use below for application.properties,

使用下面的 application.properties,

management.endpoint.health.show-details=ALWAYS

management.endpoint.health.show-details=ALWAYS

Use below for applicaton.yml,

使用下面的应用程序.yml,

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

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

回答by Ben

need to add

需要添加

management.endpoint.health.show-details=always

to Application.properties

到 Application.properties

回答by Nisarg Panchal

For Spring boot 2.X I have following in my application.properties file for detailed information:

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

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

回答by Glamdring

I had this same problem, on version Spring Boot 1.5.9 I had to set

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

management.security.enabled=false