業(yè)余在一個(gè)SpringBoot項(xiàng)目集成Swagger2時(shí),啟動(dòng)過程一直出現(xiàn)以下報(bào)錯(cuò)信息——
An attempt was made to call a method that does not exist. The attempt was made from the following location:
springfox.documentation.schema.DefaultModelDependencyProvider.dependentModels(DefaultModelDependencyProvider.java:79)
The following method did not exist:
com.google.common.collect.FluentIterable.concat(Ljava/lang/Iterable;Ljava/lang/Iterable;)Lcom/google/common/collect/FluentIterable;
The method's class, com.google.common.collect.FluentIterable, is available from the following locations:
jar:file:/C:/Users/92493/.m2/repository/com/google/guava/guava/18.0/guava-18.0.jar!/com/google/common/collect/FluentIterable.class
The class hierarchy was loaded from the following locations:
com.google.common.collect.FluentIterable: file:/C:/Users/92493/.m2/repository/com/google/guava/guava/18.0/guava-18.0.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.google.common.collect.FluentIterable
出現(xiàn)這個(gè)問題,大概猜測到,應(yīng)該是Maven依賴沖突導(dǎo)致的,忽然想到,是否有可以檢查maven依賴沖突的插件呢,一查發(fā)現(xiàn)還真有,而且極方便。
這個(gè)Idea插件,叫Maven Helper,根據(jù)File -> Settings -> Plugins -> Marketplace 輸入Maven Helper即可找到。

下載后,重啟IDEA,這時(shí)點(diǎn)擊pom.xml文件,會(huì)發(fā)現(xiàn)多了一欄【Dependency Analyzer】——

切換至【Dependency Analyzer】欄,在搜索框輸入沖突包guava,即會(huì)出現(xiàn),guava都被哪些包依賴了,當(dāng)多個(gè)組件包都依賴了同一個(gè)包但又不同版本時(shí),很容易久出現(xiàn)各種沖突。紅色部分即是導(dǎo)致啟動(dòng)報(bào)異常的地方,可見,springfox-core已經(jīng)依賴的是20.0包,但其他還依賴18版本的包,這里可以把報(bào)錯(cuò)提示的18.0版本的通過exclusion去除即可。

選中對應(yīng)想去除的包,右擊即可一鍵exclusion——

再切換至Text欄,即可發(fā)現(xiàn)已經(jīng)自動(dòng)增加了exclusions模塊——
<dependency>
<groupId>io.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-namespace</artifactId>
<version>3.1.0</version>
<exclusions>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>