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

添加grpc-server-spring-boot-starter依赖后Spring Boot应用启动失败

Spring Boot集成gRPC Starter启动报错解决

问题描述

在Spring Boot 2.1.4.RELEASE项目中添加以下gRPC服务端starter依赖后,启动服务器时抛出AbstractMethodError错误:

<dependency>
    <groupId>net.devh</groupId>
    <artifactId>grpc-server-spring-boot-starter</artifactId>
    <version>2.12.0.RELEASE</version>
</dependency>

错误日志:

org.springframework.context.ApplicationContextException: Failed to start bean 'shadedNettyGrpcServerLifecycle'; nested exception is java.lang.AbstractMethodError: io.grpc.internal.AbstractServerImplBuilder.delegate()Lio/grpc/ServerBuilder; at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:185) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:893) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:163) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]

错误原因

AbstractMethodError本质是依赖版本不兼容:

  • 你使用的grpc-server-spring-boot-starter 2.12.0.RELEASE适配Spring Boot 2.3+版本,与当前项目的Spring Boot 2.1.4.RELEASE不匹配。
  • starter依赖的gRPC核心库版本与项目中其他依赖引入的gRPC版本冲突,导致方法签名不匹配。

解决方法

方法1:调整starter版本适配Spring Boot 2.1.x

将starter版本替换为兼容Spring Boot 2.1系列的版本,比如2.5.0.RELEASE:

<dependency>
    <groupId>net.devh</groupId>
    <artifactId>grpc-server-spring-boot-starter</artifactId>
    <version>2.5.0.RELEASE</version>
</dependency>

方法2:统一gRPC核心库版本

如果不想更换starter版本,可以通过gRPC的bom来强制统一所有gRPC相关依赖的版本,避免冲突:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-bom</artifactId>
            <version>1.34.1</version> <!-- 与2.12.0.RELEASE starter兼容的版本 -->
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

方法3:清理并重建项目

执行以下命令清理旧依赖,重新构建:

mvn clean install

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 04:24:54