求助大神, spring boot 整合 swagger 报错。。。。 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ekoeko
V2EX    Java

求助大神, spring boot 整合 swagger 报错。。。。

  •  
  •   ekoeko 2017-07-04 09:32:24 +08:00 16039 次点击
    这是一个创建于 3089 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这是报错信息:

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigre/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;

    /**

    • Created by eko on 03/07/2017. */

    @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 了一天没能找到答案。。。求大神指导。

    13 条回复    2017-10-26 23:47:08 +08:00
    mineqiqi
        1
    mineqiqi  
       2017-07-04 10:29:58 +08:00
    目测 jar 包冲突?
    mineqiqi
        2
    mineqiqi  
       2017-07-04 10:30:37 +08:00
    也有可能是 JDK 不匹配?
    delavior
        3
    delavior  
       2017-07-04 10:37:16 +08:00
    guava 版本不对吧,NoSuchMethodError 啊
    pengfei
        4
    pengfei  
       2017-07-04 10:43:50 +08:00   1
    `NoSuchMethodError: com.google.common.collect.FluentIterable.toList()`
    感觉是你的 guava 版本不对,
    https://github.com/springfox/springfox/issues/441
    pengfei
        5
    pengfei  
       2017-07-04 10:46:09 +08:00
    手贱快捷键用错了
    https://github.com/springfox/springfox/issues/1055
    用`dependency:tree`检查项目中的 guava 版本, 有可能 guava 被第三方依赖引入, 建议先检查是否 guava 引入重复再升级 guava 版本
    hantsy
        6
    hantsy  
       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。
    hantsy
        7
    hantsy  
       2017-07-04 10:55:32 +08:00
    你这个应该和 Swagger 没太大的关系,没跑起来。

    ```
    java.lang.NoSuchMethodError: com.google.common.collect.FluentIterable.toList()
    ```

    guava 本身也是个坑爹的东西,版本升级又快,差几个版本之间的兼容性就不怎么样了。
    ekoeko
        8
    ekoeko  
    OP
       2017-07-04 10:56:45 +08:00
    @pengfei 谢谢你的帮助,com.google.guava:guava:jar:12.0.1:compile 版本是很低,好像是的,只有一个 guava,我看一下怎么升级。。。
    ekoeko
        9
    ekoeko  
    OP
       2017-07-04 11:12:49 +08:00
    @pengfei 我的 guava 是在 org.apache.hbase:hbase-server 中引入的,但是我更新了 hbase-server,但是 guava 并没有更新。。。
    ekoeko
        10
    ekoeko  
    OP
       2017-07-04 11:19:28 +08:00
    @hantsy 谢谢帮助,我试过 2.5 和 2.6 和 2.2.2 还是报同样的错误。。
    ekoeko
        11
    ekoeko  
    OP
       2017-07-04 11:24:53 +08:00
    @pengfei 我单独又把 guava15.0 添加到 pom.xml 中,就可以了,谢谢你!!!
    acrisliu
        12
    acrisliu  
       2017-07-04 11:34:03 +08:00
    都是好老的版本啊
    jack80342
        13
    jack80342  
       2017-10-26 23:47:08 +08:00
    最近翻译了 Spring Boot 最新的官方文档,欢迎 Fork,https://www.gitbook.com/book/jack80342/spring-boot/details
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5185 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 31ms UTC 07:03 PVG 15:03 LAX 23:03 JFK 02:03
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86