错误信息
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
springfox.documentation.spring.web.scanners.ApiListingScanner.scan(ApiListingScanner.java:117)
The following method did not exist:
com.google.common.collect.FluentIterable.append(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:/D:/apache-maven-3.8.1/repository/com/google/guava/guava/15.0/guava-15.0.jar!/com/google/common/collect/FluentIterable.class
It was loaded from the following location:
file:/D:/apache-maven-3.8.1/repository/com/google/guava/guava/15.0/guava-15.0.jar
Action:Correct the classpath of your application so that it contains a single, compatible version of com.google.common.collect.FluentIterable
Disconnected from the target VM, address: '127.0.0.1:51641', transport: 'socket'
错误是因为 springfox.documentation.spring.web.scanners.ApiListingScanner.scan 中使用了FluentIterable.apend方法,但是这个方法不存在。这样的原因肯定是版本不对到导致的。
我的swagger依赖是
<!--swagger--> <dependency><groupId>com.spring4all</groupId><artifactId>swagger-spring-boot-starter</artifactId><version>1.9.1.RELEASE</version> </dependency> <dependency><groupId>com.mangofactory</groupId><artifactId>swagger-springmvc</artifactId><version>0.9.5</version> </dependency>
原因是我的 swagger-springmvc 版本不对,0.9.5最终引用的guava版本是15.0。但是我的springfox相关依赖都是2.9.2的,导致版本对应不上。
解决方法:
一:因为我不需要 swagger-springmvc ,所以可以删除这个依赖。
二:如果一定需要使用 swagger-springmvc ,则可以在网上搜索guava/FluentIterable中存在cotcan方法相对的版本?查看maven仓库找到guava最新版本28.0直接引入。
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.0-jre</version>
</dependency>