Springfox-Swagger升級(jí)到2.9.2導(dǎo)致的NoSuchMethodError異常

2019-05-30 20:55 更新

很多朋友在將SpringFox-Swagger版本升級(jí)到2.9.2版本后,運(yùn)行程序都會(huì)出現(xiàn)如下錯(cuò)誤:

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is com.google.common.util.concurrent.ExecutionError: java.lang.NoSuchMethodError: com.google.common.collect.FluentIterable.concat(Ljava/lang/Iterable;Ljava/lang/Iterable;)Lcom/google/common/collect/FluentIterable;
    org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176)
    org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51)
    org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)
    org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)
    org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112)
    org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:851)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540)
    org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    javax.servlet.GenericServlet.init(GenericServlet.java:158)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)xxxxxxxxxx?sp-nmerrororg.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is com.google.common.util.concurrent.ExecutionError: java.lang.NoSuchMethodError: com.google.common.collect.FluentIterable.concat(Ljava/lang/Iterable;Ljava/lang/Iterable;)Lcom/google/common/collect/FluentIterable;    org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176)    org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51)    org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)    org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)    org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112)    org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:851)    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:540)    org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)    javax.servlet.GenericServlet.init(GenericServlet.java:158)    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)java

造成該錯(cuò)誤的原因是,Springfox-swagger引用的guava版本相對(duì)于你項(xiàng)目中版本較高,此時(shí)和低版本的guava引起沖突.

Springfox-Swagger中g(shù)uava的版本為20

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
<scope>compile</scope>
</dependency>

解決此錯(cuò)誤的辦法是排除低版本的guava即可.

maven命令在項(xiàng)目根目錄運(yùn)行:mvn dependency:tree命令可以看到j(luò)ar包項(xiàng)目的引用樹結(jié)構(gòu),可以看到低版本的guava是那個(gè)jar引入的

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)