2
查看DataSourceHealthIndicator
的源代碼,如果無法找出數據庫,它將使用默認查詢「SELECT 1;」到數據源的健康狀態。在Spring Boot執行程序中使用DataSourceHealthIndicator問題
此查詢在我的環境中失敗。如何將HealthCheckEndpoint
配置爲使用DatasourceHealthIndicator
進行自定義查詢。
查看DataSourceHealthIndicator
的源代碼,如果無法找出數據庫,它將使用默認查詢「SELECT 1;」到數據源的健康狀態。在Spring Boot執行程序中使用DataSourceHealthIndicator問題
此查詢在我的環境中失敗。如何將HealthCheckEndpoint
配置爲使用DatasourceHealthIndicator
進行自定義查詢。
您可以定義自己的HealthIndicator
有名dbHealthIndicator
,它將被用來代替默認情況下,像
@Bean
public HealthIndicator dbHealthIndicator() {
DataSourceHealthIndicator indicator = new DataSourceHealthIndicator(dataSource());
indicator.setQuery("Your Query Here");
return indicator;
}
注意,你可能想to share的數據庫類型和版本您使用和查詢以便可以支持開箱即用。 Boot已經爲HSQL,Derby和Oracle加上了支持「SELECT 1」的所有數據庫。
如果spring.datasource.validation-query也會被用於(設置時) 'DataSourceHealthIndicator'? –
太棒了。你能用這個建議來創建一個問題嗎?謝謝! –
雖然你輸入這個評論,我創建[這個](https://github.com/spring-projects/spring-boot/issues/1282)問題:)。 –