Reputation: 4511
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:
Health check for all the downstream APIs
Whether DB is working fine
So could anyone please help me with this? Thanks.
Upvotes: 1
Views: 9249
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