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

部署在GAE的Spring Boot API启动失败求助(Cloud Build部署)

解决Spring Boot部署GCP App Engine启动失败的依赖冲突问题

问题根源分析

从日志中的java.lang.NoSuchMethodError可以明确,核心问题是依赖版本不兼容:

  1. Guava版本过低:手动指定的Guava 19.0缺少com.google.common.io.ByteStreams.exhaust和com.google.common.base.Throwables.throwIfUnchecked方法,而依赖的Google HTTP Client等组件需要更高版本的Guava。
  2. Spring Cloud GCP依赖版本混乱:已引入3.2.1版本的BOM,却手动指定了spring-cloud-gcp-starter-sql-postgresql(1.2.4.RELEASE)和postgres-socket-factory(1.1.0)的过时版本,与Spring Boot 2.7.3不匹配。
  3. 冗余依赖冲突:手动指定的google-api-client版本与BOM管理的版本不一致,导致依赖树混乱。

修复步骤

1. 清理冗余/过时依赖

修改pom.xml,移除以下内容:

  • 手动指定的Guava依赖(让BOM自动管理兼容版本)
  • google-api-client依赖(Spring Cloud GCP Starter会自动引入适配版本)
  • spring-cloud-gcp-starter-sql-postgresql和postgres-socket-factory的手动版本号(由BOM统一管控)

2. 修正后的关键依赖片段

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-dependencies</artifactId>
            <version>3.2.1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <!-- 保留原有基础依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <!-- 恢复PostgreSQL驱动依赖 -->
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>

    <!-- 使用BOM管理的Spring Cloud GCP SQL依赖 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.cloud.sql</groupId>
        <artifactId>postgres-socket-factory</artifactId>
    </dependency>

    <!-- 保留其他业务依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <!-- ... 其余依赖保持不变 ... -->
</dependencies>

3. 验证依赖树

执行以下命令检查依赖冲突,确保Guava版本已升级到BOM管理的兼容版本:

mvn dependency:tree | grep guava

4. 重新部署

更新配置后,重新通过Cloud Build部署应用:

gcloud builds submit --config cloudbuild.yaml .

修复原理

  • Spring Cloud GCP BOM会自动维护所有GCP相关依赖的版本兼容性,彻底消除因版本不匹配导致的方法缺失问题。
  • 移除手动指定的过时版本,避免依赖树中出现多版本冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 23:20:27