業(yè)余在一個SpringBoot項目集成Swagger2時趁冈,啟動過程一直出現(xiàn)以下報錯信息——
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)這個問題喊括,大概猜測到乾蓬,應該是Maven依賴沖突導致的,忽然想到耳璧,是否有可以檢查maven依賴沖突的插件呢囱挑,一查發(fā)現(xiàn)還真有凌唬,而且極方便赁还。
這個Idea插件妖泄,叫Maven Helper,根據(jù)File -> Settings -> Plugins -> Marketplace 輸入Maven Helper即可找到艘策。
下載后蹈胡,重啟IDEA,這時點擊pom.xml文件朋蔫,會發(fā)現(xiàn)多了一欄【Dependency Analyzer】——
切換至【Dependency Analyzer】欄罚渐,在搜索框輸入沖突包guava,即會出現(xiàn)驯妄,guava都被哪些包依賴了荷并,當多個組件包都依賴了同一個包但又不同版本時,很容易久出現(xiàn)各種沖突青扔。紅色部分即是導致啟動報異常的地方源织,可見,springfox-core已經(jīng)依賴的是20.0包微猖,但其他還依賴18版本的包谈息,這里可以把報錯提示的18.0版本的通過exclusion去除即可。
選中對應想去除的包凛剥,右擊即可一鍵exclusion——
再切換至Text欄侠仇,即可發(fā)現(xiàn)已經(jī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>