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

SpringBoot中如何禁用默认gRPC健康检查并使用自定义实现

解决gRPC自定义健康检查与默认服务冲突的问题

错误核心原因是默认的gRPC健康检查服务DefaultHealthStatusService和你自定义的HealthCheckService都实现了grpc.health.v1.Health服务接口,导致Spring容器中出现重复服务定义,触发Duplicate key错误。

你可以通过以下两种方式禁用默认健康检查服务,让自定义实现生效:

方法1:通过配置文件关闭默认健康检查

在application.properties中添加配置:

grpc.health.enabled=false

或者在application.yml中配置:

grpc:
  health:
    enabled: false

方法2:排除自动配置类

在Spring Boot启动类上,排除默认健康检查的自动配置类HealthServiceAutoConfiguration:

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

完成上述配置后,重新启动应用,自定义的HealthCheckService就会正常注册并处理健康检查请求,不会再出现重复key的冲突错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 16:50:25