You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 2.7.2中ApplicationHealthIndicator是否移除?求替代方案

Spring Boot 2.7.2 仅返回UP状态的健康检查实现方案

org.springframework.boot.actuate.health.ApplicationHealthIndicator 在Spring Boot 2.7.x版本中已被移除,无需依赖该类,直接构造Health对象即可实现仅返回UP状态的健康检查。

替换后的代码如下:

@Component
@Endpoint(id = "healthcheck")
public class HealthCheckEndpoint {

    @ReadOperation
    public Health health() {
        // 直接返回UP状态的健康检查结果
        return Health.up().build();
    }
}

如果需要在返回结果中添加额外的详情信息,可以通过withDetail方法扩展:

@Component
@Endpoint(id = "healthcheck")
public class HealthCheckEndpoint {

    @ReadOperation
    public Health health() {
        return Health.up()
                .withDetail("service", "running")
                .withDetail("timestamp", System.currentTimeMillis())
                .build();
    }
}

内容的提问来源于stack exchange,提问作者Java Student

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 12:54:21