Why HATEOAS starts creating issue for spring-boot version >= 2.2.x during startup with Swagger 2.x?

前端 未结 14 2185
忘掉有多难
忘掉有多难 2020-12-09 15:18

I moved my project from spring-boot 2.1.9 to 2.2.0.

While starting the project, I am facing the below error messages.

Caused by: org.sprin         


        
相关标签:
14条回答
  • 2020-12-09 15:54

    I am using springdoc-openapi and after having encountered this problem similar to the one mentioned here:

    Description:
    
    Parameter 0 of method linkDiscoverers in org.springframework.hateoas.config.HateoasConfiguration required a single bean, but 3 were found:
        - 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
    

    I just add this dependency in my pom file

    <dependency>
        <groupId>org.springframework.hateoas</groupId>
        <artifactId>spring-hateoas</artifactId>
        <version>1.1.1.RELEASE</version>
    </dependency>
    

    hope that this can help someone

    0 讨论(0)
  • 2020-12-09 15:55

    I've removed these dependencies as a workaround and worked:

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.4.0</version>
    </dependency>
    
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.4.0</version>
    </dependency>
    

    please let me know if worked for you.

    0 讨论(0)
  • 2020-12-09 15:59

    This kind of issue is occurring due to a new feature of Hateoas.

    If you want to solve this problem , just embed the following line of codes in your swagger configuration file.

    @Primary
    @Bean
    public LinkDiscoverers discoverers() {
        List<LinkDiscoverer> plugins = new ArrayList<>();
        plugins.add(new CollectionJsonLinkDiscoverer());
        return new LinkDiscoverers(SimplePluginRegistry.create(plugins));
    }
    

    I think this is gonna solve your problem as it solved mine.

    0 讨论(0)
  • 2020-12-09 16:00

    For Spring boot version 2.1.3.RELEASE users, the following dependencies work fine for hateoas+swagger:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-hateoas</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
    
    0 讨论(0)
  • 2020-12-09 16:00

    Best Solution

    Add below code in SwaggerConfig class

    @Bean
    public LinkDiscoverers discovers() {    
        List<LinkDiscoverer> plugins = new ArrayList<>();
        plugins.add(new CollectionJsonLinkDiscoverer());
        return new LinkDiscoverers(SimplePluginRegistry.create(plugins));[enter image description here][1]  
    } 
    
    0 讨论(0)
  • 2020-12-09 16:01

    If you want Swagger, but can compromise with HATEOAS, then just remove the HATEOAS dependency and add:

    compile group: 'io.springfox', name: 'springfox-swagger-ui', version:'2.9.2'  
    compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
    
    0 讨论(0)
提交回复
热议问题