Here I am going to show how to check database health using Spring boot actuator health endpoint.

Spring Boot Actuator Database Health Check:

Include the spring boot actuator dependency in pom.xml


We can do this check in two different solutions.


Enabling the management config property in file.


Run the Application and access actuator health endpoint.


Spring Boot Actuator Database Health Check-min


Creating the custom Actuator service.

  • Creating DbHealthCheck class implementing HealthIndicator and override health() method.
  • Using JdbcTemplate, execute the sample SQL query to check whether the database connected or not.
package com.onlinetutorialspoint.actuator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.SingleColumnRowMapper;
import org.springframework.stereotype.Component;

import java.util.List;

public class DbHealthCheck implements HealthIndicator {
    JdbcTemplate template;
    public Health health() {
        int errorCode = check(); // perform some specific health check
        if (errorCode != 1) {
            return Health.down().withDetail("Error Code", 500).build();
        return Health.up().build();

    public int check(){
        List<Object> results = template.query("select 1 from dual",
                new SingleColumnRowMapper<>());
        return results.size();

Run the application.


Spring Boot Actuator Database Health Check 2-min


Spring Boot Production ready endpoints

Spring Boot Actuator

Happy Learning 🙂