【问题标题】:Implementing health check rest API using custom health indicator for Spring boot application使用 Spring Boot 应用程序的自定义健康指标实现健康检查休息 API
【发布时间】:2020-06-10 08:02:21
【问题描述】:

我正在开发在 8080 以外的端口上运行的 Spring Boot Web 应用程序。我需要编写一个 rest API 来检查应用程序以及底层数据库的健康状况。

同样的,我已经浏览了这个帖子:How to add a custom health check in spring boot health?,但没有找到任何具体的实现。

其实我想做以下事情:

  1. 所有下游 API 的健康检查

  2. DB 是否工作正常

那么有人可以帮我解决这个问题吗?谢谢。

【问题讨论】:

    标签: java spring spring-boot health-monitoring


    【解决方案1】:

    Spring boot actuator 可以自动为您创建常见的健康检查(也为您的数据库)和一个 REST API。

    要开始添加以下依赖项:

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    

    Spring boot 会在下面暴露一些执行器端点:

    /actuator
    

    与您最相关的可能是:

    /actuator/health
    

    要向此端点添加自定义运行状况检查,您可以按照链接帖子的答案中提供的指南进行操作。

    详情请见https://www.baeldung.com/spring-boot-actuators

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-27
      • 2015-07-04
      • 2023-03-10
      相关资源
      最近更新 更多