这是报错信息:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: com.google.common.collect.FluentIterable.toList()Lcom/google/common/collect/ImmutableList; at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.7.RELEASE.jar!/:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.7.RELEASE.jar!/:4.3.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.7.RELEASE.jar!/:4.3.7.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.2.RELEASE.jar!/:1.5.2.RELEASE] 。。。。。
这是我的 swagger 类:
package com.codeages.data.service.restful;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
@Configuration @EnableSwagger2 public class Swagger2 {
@Bean
public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.didispace.web"))
            .paths(PathSelectors.any())
            .build();
}
private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
            .title("test title")
            .description("test description")
            .termsOfServiceUrl("test termsOfServiceUrl")
            .contact("test contact")
            .version("test version")
            .build();
}
} 我试着去掉 @Configuration 就不报错了,但是 swagger 也不起作用了。。 我的 swagger 版本是 2.6.1,org.springframework.boot 版本 1.5.2.RELEASE。 昨天 Google 了一天没能找到答案。。。求大神指导。
|      1mineqiqi      2017-07-04 10:29:58 +08:00 目测 jar 包冲突? | 
|      2mineqiqi      2017-07-04 10:30:37 +08:00 也有可能是 JDK 不匹配? | 
|  |      3delavior      2017-07-04 10:37:16 +08:00 guava 版本不对吧,NoSuchMethodError 啊 | 
|  |      4pengfei      2017-07-04 10:43:50 +08:00  1 `NoSuchMethodError: com.google.common.collect.FluentIterable.toList()` 感觉是你的 guava 版本不对, https://github.com/springfox/springfox/issues/441 | 
|  |      5pengfei      2017-07-04 10:46:09 +08:00 手贱快捷键用错了 https://github.com/springfox/springfox/issues/1055 用`dependency:tree`检查项目中的 guava 版本, 有可能 guava 被第三方依赖引入, 建议先检查是否 guava 引入重复再升级 guava 版本 | 
|      6hantsy      2017-07-04 10:53:03 +08:00 参考: https://github.com/hantsy/angularjs-springmvc-sample-boot SpringFox 这种第三方的每个大版本变化很大,目前我的例子好像使用 Springfox 2.5,2.6 都没问题。我的例子没有升到 2.7,2.7 删除了 Springfox-staticdocs。 | 
|      7hantsy      2017-07-04 10:55:32 +08:00 你这个应该和 Swagger 没太大的关系,没跑起来。 ``` java.lang.NoSuchMethodError: com.google.common.collect.FluentIterable.toList() ``` guava 本身也是个坑爹的东西,版本升级又快,差几个版本之间的兼容性就不怎么样了。 | 
|  |      8ekoeko OP @pengfei 谢谢你的帮助,com.google.guava:guava:jar:12.0.1:compile 版本是很低,好像是的,只有一个 guava,我看一下怎么升级。。。 | 
|  |      9ekoeko OP @pengfei 我的 guava 是在 org.apache.hbase:hbase-server 中引入的,但是我更新了 hbase-server,但是 guava 并没有更新。。。 | 
|  |      12acrisliu      2017-07-04 11:34:03 +08:00 都是好老的版本啊 | 
|  |      13jack80342      2017-10-26 23:47:08 +08:00 最近翻译了 Spring Boot 最新的官方文档,欢迎 Fork,https://www.gitbook.com/book/jack80342/spring-boot/details |