Spring Boot Actuator Health Indicator

Solution 1:

As #derFuerst said the DataSourceHealthIndicator has the default query to check whether the DB is up or not.

If you want to use this the proper vendor specific query you should write your own health indicator in your configuration class, like this in case of Oracle data source:

@Autowired(required = false)
private DataSource dataSource;

@Bean
@Primary
public DataSourceHealthIndicator dataSourceHealthIndicator() {
    return new DataSourceHealthIndicator(dataSource, "SELECT 1 FROM DUAL");
}

Solution 2:

The DataSourceHealthIndicator is used to check availablity. The default query is SELECT 1, but there are some product specific queries, too.
You can write your own HealthIndicator. Either you implement the interface or extend the AbstractHealthIndicator.
To disable the default db-health-check put this line into your application properties management.health.db.enabled=false. Hope that helps

Solution 3:

The above comment helpedme to init my research but for me it was not enough :

@Bean
@Primary
public DataSourceHealthIndicator dataSourceHealthIndicator() {
    return new DataSourceHealthIndicator(dataSource, "SELECT 1 FROM DUAL");
}

Here is the configuration that helped me to make it run: Define HealthIndicator @Bean like the follow and provide the required query :

@Bean
@Primary
public HealthIndicator dbHealthIndicator() {
  return new DataSourceHealthIndicator(dataSource, "SELECT 1 FROM DUMMY");
}

If no Query is providen the SELECT 1 will be used . As #derFuerst said will be used , Here is the defailt implementation of DataSourceHealthIndicator :

public DataSourceHealthIndicator(DataSource dataSource, String query) {
    super("DataSource health check failed");
    this.dataSource = dataSource;
    this.query = query;
    this.jdbcTemplate = dataSource != null ? new JdbcTemplate(dataSource) : null;
}
...
protected String getValidationQuery(String product) {
        String query = this.query;
        if (!StringUtils.hasText(query)) {
            DatabaseDriver specific = DatabaseDriver.fromProductName(product);
            query = specific.getValidationQuery();
        }

        if (!StringUtils.hasText(query)) {
            query = "SELECT 1";
        }

        return query;
    }