首页 > 解决方案 > Spring Boot Actuator - 禁用默认调度间隔

问题描述

我正在为我的 Spring Boot 应用程序实现自定义 Actuator HealthIndicators。

它们看起来像:

public class MyClass implements HealthIndicator {

    @Override
    public Health health() {
        LOGGER.info("Checking Service Health...");
        try {
            String url = this.getExternalServiceUrl().concat("/heartbeat");
            JSONObject response = this.getResponse(url, null);
            Boolean responseSuccess = response.getBoolean("success");
            Boolean serviceAvailable = ...

            if (responseSuccess && serviceAvailable) {
                return Health.up().withDetail(...).build();
            } else {
                return Health.down().withDetail(...).build();
            }
        } catch (Exception e) {
            return Health.down().withDetail(...).build();
        }
    }
}

本质上,我的应用程序依赖于其他外部 Web 服务,当我调用我的心跳页面时,我希望它能够 ping 这些服务的心跳,并相应地更改我的应用程序的 UP 或 DOWN 状态。

我的问题是,默认情况下,Actuator 似乎有 5 分钟左右的预定时间,它会自动调用/actuator/health端点。我想禁用它。

我只想在代码中明确调用健康端点时调用它。

有谁知道如何禁用执行器默认调度?

我在用着spring-boot-actuator:2.1.3.RELEASE

标签: springspring-bootspring-boot-actuator

解决方案


Spring Boot 永远不会自动调用自己的健康端点。如果它每 5 分钟被调用一次,那么它是在您部署了正在执行此操作的应用程序的环境中。


推荐阅读