IDEA spring boot maven项目中对接swagger jar冲突解决思路

最终的pom.xml

<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger2</artifactId>
   <version>2.9.2</version>
</dependency>

<dependency>
   <groupId>com.google.guava</groupId>
   <artifactId>guava</artifactId>
   <version>27.1-jre</version>
</dependency>

问题:

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

Description:

An attempt was made to call the method com.google.common.collect.Multimaps.asMap(Lcom/google/common/collect/ListMultimap;)Ljava/util/Map; but it does not exist. Its class, com.google.common.collect.Multimaps, is available from the following locations:

    jar:file:/opt/jzy/pytha-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/hive-exec-1.2.1.jar!/com/google/common/collect/Multimaps.class
    jar:file:/opt/jzy/pytha-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/guava-20.0.jar!/com/google/common/collect/Multimaps.class

It was loaded from the following location:

    jar:file:/opt/jzy/pytha-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/hive-exec-1.2.1.jar!/


Action:

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

1.一看就是jar冲突 首先想到的是pom文件中去掉hive-exec-1.2.1,但是我的pom文件中就没有依赖它,代码中也没有用到

于是使用idea中的project structure > Libraries 去掉hive-exec-1.2.1 再次运行还是报错,再次查看project structure > Libraries

hive-exec-1.2.1 依然存在,想着用修改pom文件中的方式解决。

2.查看hive-exec-1.2.1(guava16)中引用的guava版本与springfox-swagger2(guava20)中引用的guava版本区别很大,这个时候想到hive-exec-1.2.1,我根本没用,但是他还是加载,百度了一下说pom添加guava-20.0依赖,去掉其他的guava,试了一下还是报错。

3.查看springfox-swagger2引用时看到有个更新27.1-jre版本于是添加依赖,没有做排除如上面的依赖一样,但是还是做了idea中的project structure > Libraries 去掉hive-exec-1.2.1 再次运行没有问题了,再次查看project structure > Libraries hive-exec-1.2.1 不存在了

IDEA spring boot maven项目中对接swagger jar冲突解决思路