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

Spring Boot Actuator能否在Jetty项目中使用?端点无法访问求助

解决Jetty集成Spring Boot Actuator端点无法访问的问题

核心问题定位

你当前的配置存在版本混合冲突:同时使用了Spring Boot Actuator 1.x(endpoints.health.sensitive=false)和2.x(management.endpoints.web.exposure.include=*)的配置规则;另外,management.server.port仅对Spring Boot内嵌容器生效,若你的Jetty是独立部署的传统项目,该配置完全不起作用。

排查与修复步骤

  • 统一Actuator配置版本
    先确认Spring Boot版本,对应使用一致的Actuator配置:

    • 若为Spring Boot 2.x,删除所有1.x风格配置,保留以下配置:
      management.security.enabled=false
      management.endpoints.web.exposure.include=*
      # 可选:指定端点根路径,默认是/actuator
      management.endpoints.web.base-path=/actuator
      
      注意:2.x版本健康端点默认访问路径是/actuator/health,而非1.x的/health。
    • 若为Spring Boot 1.x,保留1.x配置并删除2.x配置:
      endpoints.health.sensitive=false
      endpoints.health.enabled=true
      management.security.enabled=false
      
  • 适配Jetty部署模式

    • 如果是Spring Boot内嵌Jetty:确认9001端口未被占用,防火墙允许外部访问该端口,访问路径为http://<服务器IP>:9001/actuator/health(2.x)或http://<服务器IP>:9001/health(1.x)。
    • 如果是独立部署的Jetty:management.server.port不生效,Actuator端点与应用共享Jetty端口,访问路径为http://<服务器IP>:<Jetty应用端口>/actuator/health(2.x)或http://<服务器IP>:<Jetty应用端口>/health(1.x)。
  • 检查Servlet映射范围
    若Jetty中配置的DispatcherServlet映射路径是/app/*这类前缀路径,Actuator端点路径会自动带上该前缀,比如/app/actuator/health(2.x)或/app/health(1.x)。

  • 验证实际映射路径
    可以通过代码打印所有Spring请求映射,确认Actuator端点的真实路径:

    @Autowired
    private ApplicationContext context;
    
    @PostConstruct
    public void printAllMappings() {
        Map<String, HandlerMapping> mappingMap = context.getBeansOfType(HandlerMapping.class);
        mappingMap.values().forEach(mapping -> {
            if (mapping instanceof RequestMappingHandlerMapping) {
                ((RequestMappingHandlerMapping) mapping).getHandlerMethods().forEach((key, value) -> {
                    System.out.println("已映射路径: " + key.getPatternsCondition());
                });
            }
        });
    }
    
  • 排查端口与防火墙
    使用lsof -i :<端口号>(Linux)或netstat -ano | findstr <端口号>(Windows)检查端口占用情况,同时确认服务器防火墙未拦截目标端口的访问请求。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 13:40:27