For some reason, DataSourceHealthIndicator
does not support custom query configuration via a property.
DataSourceHealthContributorAutoConfiguration
uses poolMetadata.getValidationQuery()
to pass the validation query to DataSourceHealthIndicator
.
Using spring.datasource.hikari.connection-test-query
will customize the Hikari datasource test query and db health check will also it. However, it will also affect the performance of the Hikari connection pool which is not ideal.
Another way of configuring a custom query for DataSourceHealthIndicator
is to create this as a @Bean
manually and pass a custom query to its constructor. Using the same @Bean
name dbHealthIndicator
disables the autoconfiguration of the default DataSourceHealthIndicator. Otherwise, both default and custom versions of DataSourceHealthIndicator
can be inluded in the health check endpoint.