Spring Boot 执行器中 DataSourceHealthIndicator 的问题 [英] Issue with DataSourceHealthIndicator in Spring Boot actuator

查看:257
本文介绍了Spring Boot 执行器中 DataSourceHealthIndicator 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看DataSourceHealthIndicator 的源代码,如果它无法找出数据库,它将使用默认查询SELECT 1;"数据源的健康状态.

Looking at the source code for DataSourceHealthIndicator if it fails to figure out database it will use default query "SELECT 1;" to health status of the datasource.

此查询在我的环境中失败.如何配置 HealthCheckEndpoint 以将 DatasourceHealthIndicator 与自定义查询一起使用.

This query fails in my environment. How can I configure HealthCheckEndpoint to use DatasourceHealthIndicator with custom query.

推荐答案

您可以使用名称 dbHealthIndicator 定义您自己的 HealthIndicator 并且它将被使用而不是默认的,类似的东西

You can define your own HealthIndicator with name dbHealthIndicator and it will be used instead of the default, something like

@Bean
public HealthIndicator dbHealthIndicator() {
    DataSourceHealthIndicator indicator = new DataSourceHealthIndicator(dataSource());
    indicator.setQuery("Your Query Here");
    return indicator;
}

请注意,您可能希望分享您使用的数据库类型和版本正在使用以及哪个查询适合,以便可以开箱即用地支持.Boot 已经适用于 HSQL、Derby 和 Oracle 以及所有支持SELECT 1"的数据库

Note that you may want to share the database type and versions that you are using and which query fit so that this can be supported out-of-the-box. Boot already does for HSQL, Derby and Oracle plus all databases that support "SELECT 1"

这篇关于Spring Boot 执行器中 DataSourceHealthIndicator 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆