Swagger Error with version upgrading version > 2.6.1 – NoSuchMethodException: BasePathAwareServicesProvider.<init>()

huangapple go评论85阅读模式
英文:

Swagger Error with version upgrading version > 2.6.1 - NoSuchMethodException: BasePathAwareServicesProvider.<init>()

问题

我已经将您提供的内容翻译如下:

我已经将springfox升级到了2.7.0版本(以及2.9.2):

<springfox.version>2.7.0</springfox.version>
<spring-boot.version>1.3.3.RELEASE</spring-boot.version>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>${springfox.version}</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>${springfox.version}</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-data-rest</artifactId>
    <version>${springfox.version}</version>
</dependency>

尝试启动应用程序时,我遇到了以下错误:

org.springframework.beans.factory.UnsatisfiedDependencyException:
在URL中定义的名为'documentationPluginsBootstrapper'的bean创建错误
[jar:file:.....jar!/lib/springfox-spring-web-2.7.0.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class]:
通过构造函数参数无法满足的依赖项,索引为1,类型为[java.util.List]:在URL中定义的名为'basePathAwareServicesProvider'的bean创建错误
[jar:file:/..............!/lib/springfox-data-rest-2.7.0.jar!/springfox/documentation/spring/data/rest/BasePathAwareServicesProvider.class]:
无法实例化bean;嵌套异常是
org.springframework.beans.BeanInstantiationException:无法实例化
[springfox.documentation.spring.data.rest.BasePathAwareServicesProvider]:
找不到默认构造函数;嵌套异常是
java.lang.NoSuchMethodException:
springfox.documentation.spring.data.rest.BasePathAwareServicesProvider.();
嵌套异常是
org.springframework.beans.factory.BeanCreationException:在URL中定义的名为'basePathAwareServicesProvider'的bean创建错误
[jar:file:............!/lib/springfox-data-rest-2.7.0.jar!/springfox/documentation/spring/data/rest/BasePathAwareServicesProvider.class]:
无法实例化bean;嵌套异常是
org.springframework.beans.BeanInstantiationException:无法实例化
[springfox.documentation.spring.data.rest.BasePathAwareServicesProvider]:
找不到默认构造函数;嵌套异常是
java.lang.NoSuchMethodException:
springfox.documentation.spring.data.rest.
BasePathAwareServicesProvider.init()

找不到默认构造函数;BasePathAwareServicesProvider.init()

为了避免与swaggers-ui.html出现一些错误,我已经对类进行了如下注解:

@Configuration
@Profile("swaggerEnabled")
@EnableSwagger2
@EnableWebMvc
@Import(SpringDataRestConfiguration.class)
public class SwaggerConfiguration {

Springboot应用程序:

@EnableSwagger2
@EnableWebMvc
@SpringBootApplication
@Import(value = {
        ......class,})
@Order(Ordered.HIGHEST_PRECEDENCE)
@ComponentScan(basePackages = {"....."})
public class PlatformApiApplication {

我尝试了一些来自GitHub的解决方案,但都没有奏效。有人可以帮助我吗?谢谢。

英文:

I have upgraded springfox to version 2.7.0(and 2.9.2):

&lt;springfox.version&gt;2.7.0&lt;/springfox.version&gt;
&lt;spring-boot.version&gt;1.3.3.RELEASE&lt;/spring-boot.version&gt;
&lt;dependency&gt;
    &lt;groupId&gt;io.springfox&lt;/groupId&gt;
    &lt;artifactId&gt;springfox-swagger-ui&lt;/artifactId&gt;
    &lt;version&gt;${springfox.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;io.springfox&lt;/groupId&gt;
    &lt;artifactId&gt;springfox-swagger2&lt;/artifactId&gt;
    &lt;version&gt;${springfox.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;io.springfox&lt;/groupId&gt;
    &lt;artifactId&gt;springfox-data-rest&lt;/artifactId&gt;
    &lt;version&gt;${springfox.version}&lt;/version&gt;
&lt;/dependency&gt;

and trying to start the application I get the next error:

> org.springframework.beans.factory.UnsatisfiedDependencyException:
> Error creating bean with name 'documentationPluginsBootstrapper'
> defined in URL
> [jar:file:.....jar!/lib/springfox-spring-web-2.7.0.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class]:
> Unsatisfied dependency expressed through constructor argument with
> index 1 of type [java.util.List]: Error creating bean with name
> 'basePathAwareServicesProvider' defined in URL
> [jar:file:/..............!/lib/springfox-data-rest-2.7.0.jar!/springfox/documentation/spring/data/rest/BasePathAwareServicesProvider.class]:
> Instantiation of bean failed; nested exception is
> org.springframework.beans.BeanInstantiationException: Failed to
> instantiate
> [springfox.documentation.spring.data.rest.BasePathAwareServicesProvider]:
> No default constructor found; nested exception is
> java.lang.NoSuchMethodException:
> springfox.documentation.spring.data.rest.BasePathAwareServicesProvider.<init>();
> nested exception is
> org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name 'basePathAwareServicesProvider' defined in URL
> [jar:file:............!/lib/springfox-data-rest-2.7.0.jar!/springfox/documentation/spring/data/rest/BasePathAwareServicesProvider.class]:
> Instantiation of bean failed; nested exception is
> org.springframework.beans.BeanInstantiationException: Failed to
> instantiate
> [springfox.documentation.spring.data.rest.BasePathAwareServicesProvider]:
> No default constructor found; nested exception is
> java.lang.NoSuchMethodException:
> springfox.documentation.spring.data.rest.
BasePathAwareServicesProvider. init ()

No default constructor found; BasePathAwareServicesProvider. init ()

I have annotated the classes like this in order to avoid some errors with swaggers-ui.html:

@Configuration
@Profile(&quot;swaggerEnabled&quot;)
@EnableSwagger2
@EnableWebMvc
@Import(SpringDataRestConfiguration.class)
public class SwaggerConfiguration {

The Springboot application:

@EnableSwagger2
@EnableWebMvc
@SpringBootApplication
@Import(value = {
        ......class,})
@Order(Ordered.HIGHEST_PRECEDENCE)
@ComponentScan(basePackages = {&quot;.....&quot;})
public class PlatformApiApplication {

I've tried some solutions from github but nothing works. Can somebody help me? thanks.

答案1

得分: 0

移除这一行:

@Import(SpringDataRestConfiguration.class)

错误消失。

英文:

Removing the line:

@Import(SpringDataRestConfiguration.class)

The error dissapears

huangapple
  • 本文由 发表于 2020年6月6日 00:53:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/62220426.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定