使用自定义的健康指示器为Spring引导应用程序实现健康检查休息API。

问题描述 投票:0回答:1

我正在处理Spring Boot网络应用程序,它的端口不是 8080. 我需要写一个休息API来检查应用程序以及底层数据库的健康状况。

关于同样的问题,我已经看了这个帖子。如何在spring boot health中添加一个自定义的健康检查?但没有找到任何具体的实现。

实际上,我想做以下工作。

  1. 对所有下游API进行健康检查

  2. 数据库是否正常运行

那么谁能帮我解决这个问题呢?谢谢。

java spring spring-boot health-monitoring
1个回答
1
投票

Spring Boot actuator可以自动为你创建普通的健康检查(也为你的数据库)和REST API。

要开始,请添加以下依赖关系。

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

然后Spring boot会暴露一些actuator端点下。

/actuator

对你来说,最相关的可能是。

/actuator/health

要为这个端点添加一个自定义的健康检查,你可以按照你的链接帖子的答案中提供的指南进行操作。

更多细节,请看 https:/www.baeldung.comspring-boot-actuators.

© www.soinside.com 2019 - 2024. All rights reserved.