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

非Web Spring Boot GRPC服务器配置JMX Actuator健康检查失败

解决Spring Boot独立gRPC服务JMX健康检查端点不可见问题

针对搭建独立gRPC服务时JMX健康检查MBean无法被jconsole识别的问题,可按以下步骤排查解决:

1. 调整依赖配置

将Actuator的依赖从runtimeOnly改为implementation,确保自动配置类能被正确加载:

implementation 'org.springframework.boot:spring-boot-starter-actuator'
// implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'

2. 完善JMX相关配置

在application.yaml中补充必要的JMX配置,确保端点正确暴露:

spring:
  main:
    banner-mode: "off"
    web-application-type: none
  jmx:
    enabled: true
    default-domain: your-service-domain # 自定义MBean域名,方便在jconsole中定位
management:
  endpoint:
    health:
      enabled: true
      show-details: always # 可选,开启后显示健康检查详情
  endpoints:
    jmx:
      exposure:
        include: health
      domain: your-management-domain # 可选,单独指定管理端点的JMX域名
  jmx:
    enabled: true

3. 添加JVM启动参数

启动应用时需开启JMX远程连接支持,在JVM参数中添加:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9090 # 自定义端口,避免与其他服务冲突
-Dcom.sun.management.jmxremote.authenticate=false # 开发环境可关闭认证,生产环境需启用
-Dcom.sun.management.jmxremote.ssl=false # 开发环境可关闭SSL,生产环境需启用

4. 验证自动配置生效

在application.yaml中添加debug: true,启动应用后查看控制台输出的自动配置报告,确认JmxEndpointAutoConfiguration和HealthEndpointAutoConfiguration标记为PositiveMatches。若为NegativeMatches,需检查是否存在自动配置排除规则或依赖缺失。

5. 确认启动类配置

确保启动类标注@SpringBootApplication,并通过SpringApplication.run标准方式启动:

@SpringBootApplication
public class GrpcServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(GrpcServerApplication.class, args);
    }

    // gRPC服务相关配置Bean...
}

原因分析

当web-application-type: none时,Spring Boot会禁用Web相关自动配置,但Actuator的JMX端点依赖的配置类需要确保JMX功能开启且加载正常。此外,JVM默认未开启远程JMX连接,会导致jconsole无法发现目标MBean。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 01:06:30