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

Spring Boot从2.0升级到2.7.5后Actuator/health端点返回DOWN状态求助

Actuator /health端点返回DOWN的解决办法

1. 开启健康详情定位故障

默认Spring Boot 2.x的/actuator/health只返回简洁状态,无法看到具体故障组件。先在配置文件中开启详情展示:

# application.properties
management.endpoint.health.show-details=always
management.endpoint.health.show-components=always

或YAML格式:

# application.yaml
management:
  endpoint:
    health:
      show-details: always
      show-components: always

重新访问端点后,就能看到每个健康检查组件的状态,直接定位导致整体状态DOWN的具体模块。

2. 排查自动注册的健康指示器

Spring Boot Actuator会自动为数据库、Redis、MQ等依赖组件注册健康指示器,若对应服务未启动或配置错误,会触发该指示器返回DOWN,进而导致整体状态异常:

  • 查看应用启动日志,检索含HealthIndicator的日志条目,定位检查失败的组件
  • 若某些组件无需健康检查,可直接禁用对应指示器:
    # 示例:禁用Redis健康检查
    management.health.redis.enabled=false
    

3. 验证自定义健康指示器逻辑

如果项目中有自定义HealthIndicator实现类,检查其逻辑是否因Spring Boot版本升级出现适配问题:

  • 确认Health.Builder等API的调用方式是否符合2.7.x版本规范
  • 排查自定义逻辑中是否存在误判DOWN状态的情况

4. 排查Swagger配置与Actuator的冲突

之前为解决Swagger的documentationPluginsBootstrapper问题添加的Bean或配置,可能影响Actuator的正常运行:

  • 检查新增的WebMvcEndpointHandlerMapping相关Bean,确认未干扰Actuator端点的初始化
  • 确认Swagger配置类未误排除Actuator的自动配置类

5. 确认Actuator端点暴露配置

确保/health端点已被正确暴露:

# 仅暴露health端点
management.endpoints.web.exposure.include=health
# 暴露所有端点(生产环境谨慎使用)
management.endpoints.web.exposure.include=*

6. 调整Spring Security配置(若使用)

升级后Spring Security的配置规则可能需要适配,确保Actuator端点可正常访问:

@Configuration
public class SecurityConfig {
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests(auth -> auth
                .requestMatchers("/actuator/**").permitAll()
                .anyRequest().authenticated());
        return http.build();
    }
}

(注:Spring Boot 2.7.x中WebSecurityConfigurerAdapter已标记为Deprecated,推荐使用上述新配置方式)


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 13:01:55