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

Spring Boot Actuator提示暴露0端点 health接口404异常排查

Spring Boot Actuator 0端点暴露、/actuator/health返回404排查方案

问题现象

  • 应用启动打印INFO日志:Exposing 0 endpoint(s) beneath base path '/actuator',完整日志如下:
{"@timestamp":"2022-06-29T09:50:59.441+02:00","@version":1,"message":"Exposing 0 endpoint(s) beneath base path '/actuator'","logger_name":"org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver","thread_name":"main","level":"INFO","level_value":20000,"caller_class_name":"org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver","caller_method_name":"<init>","caller_file_name":"EndpointLinksResolver.java","caller_line_number":58}
  • 访问/actuator/health返回404状态码,访问/actuator根路径仅返回自身链接,无任何已暴露端点:
{"_links":{"self":{"href":"http://localhost:8000/actuator","templated":false}}}

已验证无效的排查方向

  • 注释所有自定义@RestController的接口映射,排除接口路径冲突,问题未解决
  • 依赖配置正常,使用Spring Boot 2.6.6版本,已引入web和actuator starter:
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.6</version>
        <relativePath />
</parent>

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
  • application.yaml已按规范配置端点暴露规则,且配置可正常生效(端口配置已生效):
server:
  port: 8000

management:
  health:
    probes:
      enabled: true
    livenessstate:
      enabled: true
    readinessstate:
      enabled: true

  endpoint:
    health:
      probes:
        enabled: true
      show-details: always
      enabled: true

  endpoints:
    web:
      exposure:
        include: '*'
    enabled-by-default: true

排查步骤与解决方案

按优先级从高到低逐一排查:

  1. 检查是否存在@EnableWebMvc注解
    这是该场景下最高频的触发原因:只要项目中任意配置类标注了@EnableWebMvc,Spring Boot默认的MVC自动配置就会完全失效,其中就包含Actuator端点的Web层注册逻辑,直接导致0端点暴露。
    直接删除所有自定义位置的@EnableWebMvc注解即可。如果需要自定义MVC配置(比如拦截器、跨域规则),直接实现WebMvcConfigurer接口即可,不需要加@EnableWebMvc。
  2. 校验Actuator配置是否被覆盖
    虽然端口配置生效,不代表Actuator相关配置没有被其他配置源覆盖:
    • 检查是否有其他环境配置文件(比如application-dev.yaml、application-prod.yaml)、配置中心(Nacos/Apollo等)的远程配置覆盖了management.endpoints.web.exposure.include、management.endpoints.enabled-by-default配置项
    • 临时开启Actuator的debug日志,启动后观察端点加载过程:
      logging:
        level:
          org.springframework.boot.actuate: DEBUG
      
      启动后搜索日志中WebEndpointAutoConfiguration相关输出,查看自动配置是否因条件不满足被跳过,同时确认端点暴露配置的实际加载值。
  3. 检查包扫描规则配置
    如果启动类上的@SpringBootApplication注解显式配置了scanBasePackages属性,或者额外添加了@ComponentScan注解限定扫描范围,确保没有把Actuator的自动配置类排除在扫描范围外。
    最稳妥的做法是将启动类放在所有自定义业务类的根包路径下,使用Spring Boot默认的包扫描规则,不要随意自定义扫描范围。
  4. 排查拦截器、安全框架影响
    临时注释所有自定义的HandlerInterceptor、Filter注册逻辑,临时移除Spring Security、Shiro等安全框架依赖,重启测试端点是否正常加载。如果移除后恢复正常,说明是拦截/安全逻辑影响了端点初始化,需要针对Actuator路径配置放行规则。
  5. 排查依赖冲突
    执行mvn dependency:tree查看全量依赖树,排查是否存在以下问题:
    • 多版本spring-boot-actuator-*相关包被引入,产生版本冲突
    • 第三方依赖传递引入了低版本的spring-web、spring-context等核心包,覆盖了Spring Boot 2.6.6自带的兼容版本,导致自动配置类加载失败

修复验证标准

重启应用后,启动日志出现Exposing [大于1的数字] endpoint(s) beneath base path '/actuator'的输出,访问/actuator能看到health等端点的链接,访问/actuator/health可正常返回服务健康状态。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.28 16:54:42