项目引入 swagger 启动报错处理(An attempt was made to call the method com.google.common.collect.FluentIterable)

背景介绍

我用的springboot框架,是用maven构建的项目,加入swagger依赖的时候启动的时候报错

报错信息:


***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call the method com.google.common.collect.FluentIterable.concat(Ljava/lang/Iterable;Ljava/lang/Iterable;)Lcom/google/common/collect/FluentIterable; but it does not exist. Its class, com.google.common.collect.FluentIterable, is available from the following locations:

    jar:file:/repository/com/google/guava/guava/19.0/guava-19.0.jar!/com/google/common/collect/FluentIterable.class

It was loaded from the following location:

    file:/repository/com/google/guava/guava/19.0/guava-19.0.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of com.google.common.collect.FluentIterable


Process finished with exit code 0

定位原因:

根据错误定位是jar包冲突,

1、执行maven命令查看项目jar包依赖关系

mvn dependency:tree >tree.log

2、依赖引用分析发现有多个地方引用了guava

--nacos-client

项目引入 swagger 启动报错处理(An attempt was made to call the method com.google.common.collect.FluentIterable)_第1张图片

--swagger

项目引入 swagger 启动报错处理(An attempt was made to call the method com.google.common.collect.FluentIterable)_第2张图片

解决方案:

在启动项目模块中pom.xml 指定guava版本,重新启动项目。

         
            com.google.guava
            guava
            29.0-jre
        

 

 

你可能感兴趣的:(JAVA,java,maven,bug,spring,boot,jar)