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

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

}

最佳答案

根据 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.sensitive to 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

https://stackoverflow.com/questions/32971182/

相关文章:

java - 无法实例化 Pageable bean

spring - 禁用 Spring 日志,以获得可读日志

java - Spring MVC 缺少 URI 模板变量

java - 事务注释在 Spring Boot 中不起作用

spring - 使用 Java 注释使用 Spring 发送电子邮件

java - 在 @Configuration 类中的 Spring 中设置注释驱动的事务

spring - 如何在 Spring Boot Jackson 日期序列化中应用默认时区

java - Spring security - 禁用注销重定向

java - spring 是否有一个关闭过程来放置清理代码?

java - Maven:没有要编译的资源