Swagger Spring Boot 版本一致问题

Swagger Spring Boot 版本一致问题

异常信息

[2020-03-23 18:39:00.603] boot -  INFO [background-preinit] --- Version: HV000001: Hibernate Validator 6.0.18.Final

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.5.RELEASE)

[2020-03-23 18:39:01.012] boot -  INFO [main] --- DemocApplication: Starting DemocApplication on root-PC with PID 2676 (D:\nanligong\mianshi\project\easy_code\democ\target\classes started by Administrator in D:\nanligong\mianshi\project\easy_code)
[2020-03-23 18:39:01.016] boot -  INFO [main] --- DemocApplication: No active profile set, falling back to default profiles: default
[2020-03-23 18:39:03.711] boot -  INFO [main] --- TomcatWebServer: Tomcat initialized with port(s): 8081 (http)
[2020-03-23 18:39:03.820] boot -  INFO [main] --- ContextLoader: Root WebApplicationContext: initialization completed in 2719 ms
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
[2020-03-23 18:39:03.999] boot -  INFO [main] --- DruidDataSourceAutoConfigure: Init DruidDataSource
[2020-03-23 18:39:04.137] boot -  INFO [main] --- DruidDataSource: {dataSource-1} inited
Using VFS adapter tk.mybatis.mapper.autoconfigure.SpringBootVFS
Checking to see if class com.example.democ.entity.User matches criteria [is assignable to Object]
Scanned package: 'com.example.democ.entity' for aliases
Parsed mapper file: 'file [D:\nanligong\mianshi\project\easy_code\democ\target\classes\mapper\UserDao.xml]'
[2020-03-23 18:39:05.180] boot -  INFO [main] --- ThreadPoolTaskExecutor: Initializing ExecutorService 'applicationTaskExecutor'
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
[2020-03-23 18:39:05.501] boot -  WARN [main] --- AnnotationConfigServletWebServerApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'linkDiscoverers' defined in class path resource [org/springframework/hateoas/config/HateoasConfiguration.class]: Unsatisfied dependency expressed through method 'linkDiscoverers' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.plugin.core.PluginRegistry<org.springframework.hateoas.client.LinkDiscoverer, org.springframework.http.MediaType>' available: expected single matching bean but found 15: modelBuilderPluginRegistry,modelPropertyBuilderPluginRegistry,typeNameProviderPluginRegistry,documentationPluginRegistry,apiListingBuilderPluginRegistry,operationBuilderPluginRegistry,parameterBuilderPluginRegistry,expandedParameterBuilderPluginRegistry,resourceGroupingStrategyRegistry,operationModelsProviderPluginRegistry,defaultsProviderPluginRegistry,pathDecoratorRegistry,relProviderPluginRegistry,linkDiscovererRegistry,entityLinksPluginRegistry
[2020-03-23 18:39:05.509] boot -  INFO [main] --- ThreadPoolTaskExecutor: Shutting down ExecutorService 'applicationTaskExecutor'
[2020-03-23 18:39:05.512] boot -  INFO [main] --- DruidDataSource: {dataSource-1} closed
[2020-03-23 18:39:05.526] boot -  INFO [main] --- ConditionEvaluationReportLoggingListener: 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[2020-03-23 18:39:05.531] boot - ERROR [main] --- LoggingFailureAnalysisReporter: 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method linkDiscoverers in org.springframework.hateoas.config.HateoasConfiguration required a single bean, but 15 were found:
	- modelBuilderPluginRegistry: defined in null
	- modelPropertyBuilderPluginRegistry: defined in null
	- typeNameProviderPluginRegistry: defined in null
	- documentationPluginRegistry: defined in null
	- apiListingBuilderPluginRegistry: defined in null
	- operationBuilderPluginRegistry: defined in null
	- parameterBuilderPluginRegistry: defined in null
	- expandedParameterBuilderPluginRegistry: defined in null
	- resourceGroupingStrategyRegistry: defined in null
	- operationModelsProviderPluginRegistry: defined in null
	- defaultsProviderPluginRegistry: defined in null
	- pathDecoratorRegistry: defined in null
	- relProviderPluginRegistry: defined by method 'relProviderPluginRegistry' in class path resource [org/springframework/hateoas/config/HateoasConfiguration.class]
	- linkDiscovererRegistry: defined in null
	- entityLinksPluginRegistry: defined by method 'entityLinksPluginRegistry' in class path resource [org/springframework/hateoas/config/WebMvcEntityLinksConfiguration.class]


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed


Process finished with exit code 1

原因

Swagger Spring Boot 版本不一致

解决方法

去官网搜索Swagger 和Spring Boot匹配的版本。比如下面是我测试可以使用的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>democ</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>democ</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <swagger.version>2.9.2</swagger.version>
    </properties>

    <dependencies>
        <!--引入SpringBoot起步依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
           
        </dependency>
      

        <!--swagger-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger.version}</version>
        </dependency>

    </dependencies>
    


</project>

总结

平时可以收集pom文件。测试通过以后,也防止出现业务以外莫名的错误。

发布了22 篇原创文章 · 获赞 4 · 访问量 22万+

猜你喜欢

转载自blog.csdn.net/qq_32510597/article/details/105054876