【问题标题】:springboot rest swagger :error in initialising beanspring boot rest swagger:初始化bean时出错
【发布时间】:2020-03-31 18:13:16
【问题描述】:

我正在使用 swagger 来记录我的 Spring Boot Rest 应用程序 使用

  • spring-boot-starter-web
  • spring-boot-starter-data-rest
  • springfox-swagger2 2.9.2
  • springfox-swagger 2.9.2

代码构建良好,但是当我运行它时,它在下面抛出错误

org.springframework.beans.factory.UnsatisfiedDependencyException: 
    Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration 

$EnableWebMvcConfiguration.class]:
 Unsatisfied dependency expressed through method 'requestMappingHandlerMapping' parameter 1;
nested exception is org.springframework.beans.factory.BeanCreationException:
 Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration

$EnableWebMvcConfiguration.class]:
 Bean instantiation via factory method failed;
 nested exception is org.springframework.beans.BeanInstantiationException:
 Failed to instantiate [org.springframework.format.support.FormattingConversionService]: 
Factory method 'mvcConversionService' threw exception; 
nested exception is org.springframework.beans.factory.BeanCreationException:
 Error creating bean with name 'jsonSchemaConverter' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]:
     Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException:
 Failed to instantiate [org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter]:
     Factory method 'jsonSchemaConverter' threw exception;
nested exception is org.springframework.beans.factory.BeanCreationException: 
     Error creating bean with name 'defaultConversionService' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]:
     Bean instantiation via factory method failed;  
nested exception is org.springframework.beans.BeanInstantiationException: 
     Failed to instantiate [org.springframework.format.support.DefaultFormattingConversionService]:
     Factory method 'defaultConversionService' threw exception; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
     Error creating bean with name 'repositoryInvokerFactory' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]:
     Bean instantiation via factory method failed;

nested exception is org.springframework.beans.BeanInstantiationException:
 nested exception is org.springframework.beans.BeanInstantiationException:
     Failed to instantiate [org.springframework.data.repository.support.RepositoryInvokerFactory]:
     Factory method 'repositoryInvokerFactory' threw exception;

nested exception is java.lang.NoSuchMethodError:      org.springframework.plugin.core.PluginRegistry.of(Ljava/util/List;)Lorg/springframework/plugin/core/PluginRegistry;   

【问题讨论】:

    标签: rest spring-boot swagger


    【解决方案1】:

    我遇到了同样的问题。这是我的解决方法:

    TL/DR:

    Springfox 使用过时的 spring-plugin-core 版本,与 spring boot 2.2.5 不兼容。 Springfox 似乎不再维护;迁移到不同的spring-swagger-bridge,比如Springdoc-openapi:https://springdoc.github.io/springdoc-openapi-demos/


    相关输出

    nested exception is org.springframework.beans.BeanInstantiationException:
    Failed to instantiate [org.springframework.data.repository.support.RepositoryInvokerFactory]:
    Factory method 'repositoryInvokerFactory' threw exception; nested exception is java.lang.NoSuchMethodError:
    'org.springframework.plugin.core.PluginRegistry org.springframework.plugin.core.PluginRegistry.of(java.util.List)'
    

    来自NoSuchMethodError: org.springframework.plugin.core.PluginRegistry.getPluginOrDefaultFor:

    ...一个疯狂的猜测是 springfox 的最后一个工作版本(为您和我们工作)是使用低于 2.2.2 的 Spring boot 版本编译的。该启动版本具有不同的 getPluginOrDefaultFor 方法签名(或者该方法可能根本不存在)。


    原因

    • springfox 导入 1.2.0 版的 spring-plugin-core。 Spring Boot 2.2.5 需要 2.0.0.RELEASE 版本
    • springfox中标进口彩票;测试失败 b/c Spring Boot 找不到它的方法。
    • 显式导入 2.0.0.RELEASE 会使 springfox 死掉。
    • springfox的最新版本是2.9.2;即使 3.0.0-SNAPSHOT 也不能解决问题:https://github.com/springfox/springfox/issues/2932


    解决方案

    是的,我最终找到了“springDoc”的链接并找到了一个 快速教程。 在 pom.xml 文件中设置所有内容非常容易。 只需要一次调整
    <!-- org.springdoc for swagger setup  -->
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-core</artifactId>
        <version>1.1.49</version>
        <exclusions>
            <exclusion>
                <groupId>io.github.classgraph</groupId>
                <artifactId>classgraph</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.1.49</version>
    </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      • 2023-03-02
      • 1970-01-01
      • 1970-01-01
      • 2019-05-30
      相关资源
      最近更新 更多