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

Spring Boot-Maven-Java应用启动失败:类路径依赖版本兼容问题

解决Spring Boot-Maven项目中Guava与Google Collections冲突问题

问题根源

类路径中同时存在google-collections-1.0.jar和guava-30.1.1-jre.jar,google-collections是Guava的旧版前身,其ImmutableMap类没有toImmutableMap方法,系统优先加载了旧版本导致启动报错。

解决方案

1. 排除间接依赖的google-collections

在pom.xml中找到引入google-collections的依赖(通常是间接依赖),添加排除配置:

<dependency>
    <!-- 替换为实际引入google-collections的依赖坐标 -->
    <groupId>对应依赖组ID</groupId>
    <artifactId>对应依赖 artifactID</artifactId>
    <version>对应版本号</version>
    <exclusions>
        <exclusion>
            <groupId>com.google.collections</groupId>
            <artifactId>google-collections</artifactId>
        </exclusion>
    </exclusions>
</dependency>

2. 强制锁定Guava版本

在pom.xml的<dependencyManagement>节点中添加Guava版本锁定,确保所有依赖统一使用指定版本:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>30.1.1-jre</version>
        </dependency>
    </dependencies>
</dependencyManagement>

3. 定位冲突依赖来源

执行Maven命令生成依赖树,精准找到引入google-collections的依赖:

mvn dependency:tree -Dincludes=com.google.collections:google-collections

根据输出结果,对对应的依赖添加排除配置。

4. 清理本地仓库缓存

若本地Maven仓库存在旧版本依赖缓存,清理后重新构建:

mvn clean install -U

验证方式

执行mvn dependency:list命令,检查输出中是否仅存在guava-30.1.1-jre.jar,无google-collections-1.0.jar。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 19:17:04