1

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.

Joy
  • 4,197
  • 14
  • 61
  • 131

1 Answers1

1

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.

meva
  • 183
  • 1
  • 1
  • 16