Joy
Joy

Reputation: 4511

Implementing health check rest API using custom health indicator for Spring boot application

I am working on Spring Boot web application running on a port other than 8080. I need to write a rest API for checking the health of the application as well as the underlying database.

Regarding the same, I have gone through this post: How to add a custom health check in spring boot health?, but did not find any concrete implementation.

Actually I would like to do following:

  1. Health check for all the downstream APIs

  2. Whether DB is working fine

So could anyone please help me with this? Thanks.

Upvotes: 1

Views: 9249

Answers (1)

meva
meva

Reputation: 333

Spring boot actuator can automatically create common health checks (also for your database) and a REST API for you.

To get started add the following dependency:

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

Spring boot will then expose some actuator endpoints under:

/actuator

The most relevant for you is probably:

/actuator/health

To add a custom health check to this endpoint, you can follow the guide provided in the answer to your linked post.

For more details, please see https://www.baeldung.com/spring-boot-actuators.

Upvotes: 1

Related Questions