在 Spring Actuator 中禁用特定数据源的 HealtCheck

Joz*_*oko 3 java spring datasource spring-boot spring-boot-actuator

我在禁用 Spring Actuator 中的特定数据源时遇到问题。我目前的应用程序中有一个任务是实现 Spring Actuator,但需要 Actuator 来忽略/禁用应用程序中的某些功能(主要是健康指示器)。应用程序是从其他迷你应用程序构建的。有什么建议或说明如何开始吗?

Bhu*_*yal 7

禁用默认数据源运行状况指示器

management.health.db.enabled=false
Run Code Online (Sandbox Code Playgroud)

并使用 DataSourceHealthIndicator 自定义您所需的数据源

例子:

@Autowired
private DataSource requiredDataSource;

@Bean
public DataSourceHealthIndicator requiredDataSourceHealthIndicator() {
    return new DataSourceHealthIndicator(requiredDataSource);
}
Run Code Online (Sandbox Code Playgroud)