Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.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 17: modelBuilderPluginRegistry,modelPropertyBuilderPluginRegistry,typeNameProviderPluginRegistry,syntheticModelProviderPluginRegistry,documentationPluginRegistry,apiListingBuilderPluginRegistry,operationBuilderPluginRegistry,parameterBuilderPluginRegistry,expandedParameterBuilderPluginRegistry,resourceGroupingStrategyRegistry,operationModelsProviderPluginRegistry,defaultsProviderPluginRegistry,pathDecoratorRegistry,apiListingScannerPluginRegistry,relProviderPluginRegistry,linkDiscovererRegistry,entityLinksPluginRegistry   Caused by: 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 17: modelBuilderPluginRegistry,modelPropertyBuilderPluginRegistry,typeNameProviderPluginRegistry,syntheticModelProviderPluginRegistry,documentationPluginRegistry,apiListingBuilderPluginRegistry,operationBuilderPluginRegistry,parameterBuilderPluginRegistry,expandedParameterBuilderPluginRegistry,resourceGroupingStrategyRegistry,operationModelsProviderPluginRegistry,defaultsProviderPluginRegistry,pathDecoratorRegistry,apiListingScannerPluginRegistry,relProviderPluginRegistry,linkDiscovererRegistry,entityLinksPluginRegistry   *************************** APPLICATION FAILED TO START ***************************  Description:   Parameter 0 of method linkDiscoverers in org.springframework.hateoas.config.HateoasConfiguration  required a single bean, but 17 were found: - modelBuilderPluginRegistry: defined in null - modelPropertyBuilderPluginRegistry: defined in null - typeNameProviderPluginRegistry: defined in null - syntheticModelProviderPluginRegistry: 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 - apiListingScannerPluginRegistry: 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] 

What could have caused this issue ?

Note: I am not using HATEOAS in my pom.xml file.

pom.xml

<properties>     <java.version>1.8</java.version>     <swagger-springfox.version>2.9.2</swagger-springfox.version>     <sonar.jacoco.execPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.execPath>     <jasypt-spring-boot-starter>2.1.1</jasypt-spring-boot-starter>     <logbook-spring-boot-starter>1.13.0</logbook-spring-boot-starter>     <assertj-swagger>0.8.1</assertj-swagger>     <jacoco-version>0.8.4</jacoco-version> </properties> <dependencies>     <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-actuator</artifactId>     </dependency>     <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-data-jpa</artifactId>     </dependency>     <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-data-rest</artifactId>     </dependency>     <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-devtools</artifactId>         <scope>runtime</scope>     </dependency>     <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-configuration-processor</artifactId>     </dependency>     <dependency>         <groupId>org.projectlombok</groupId>         <artifactId>lombok</artifactId>         <optional>true</optional>     </dependency>     <dependency>         <groupId>org.springframework.boot</groupId>         <artifactId>spring-boot-starter-test</artifactId>         <scope>test</scope>     </dependency>     <dependency>         <groupId>io.springfox</groupId>         <artifactId>springfox-swagger2</artifactId>         <version>${swagger-springfox.version}</version>     </dependency>     <dependency>         <groupId>io.springfox</groupId>         <artifactId>springfox-swagger-ui</artifactId>         <version>${swagger-springfox.version}</version>     </dependency>     <dependency>         <groupId>io.springfox</groupId>         <artifactId>springfox-spring-web</artifactId>         <version>${swagger-springfox.version}</version>     </dependency>     <dependency>         <groupId>io.springfox</groupId>         <artifactId>springfox-core</artifactId>         <version>${swagger-springfox.version}</version>     </dependency>     <dependency>         <groupId>io.springfox</groupId>         <artifactId>springfox-data-rest</artifactId>         <version>${swagger-springfox.version}</version>     </dependency>     <dependency>         <groupId>io.springfox</groupId>         <artifactId>springfox-bean-validators</artifactId>         <version>${swagger-springfox.version}</version>     </dependency> 
like image 266
VIJ Avatar asked Oct 17 '19 11:10

VIJ


People also ask

How do you implement HATEOAS in REST spring boot?

To implement HATEOAS, we would need to include related resources in the response. Instead of Student we use a return type of EntityModel<Student> . EntityModel is a simple class wrapping a domain object and allows adding links to it. We create a new resource.

What is spring boot starter HATEOAS?

The Spring HATEOAS project is a library of APIs that we can use to easily create REST representations that follow the principle of HATEOAS (Hypertext as the Engine of Application State).

Should I use spring HATEOAS?

Spring HATEOAS provides common abstractions (representational models, a Link class, API to build links pointing to Spring MVC controllers, etc.) to ease building hypermedia driven REST APIs with Spring MVC in general. Thus, you can use it alongside Spring MVC to manually build those services.

In which Spring Library is HATEOAS implemented?

Spring-HATEOAS is the library of APIs. We can use these APIs for creating REST representations that follow the HATEOAS principle while working with Spring MVC.


2 Answers

I had this issue with Swagger + HATEOAS in my spring-boot application.

The fix is given below (edit your Swagger configuration class):

@Configuration @EnableSwagger2 public class SwaggerConfiguration {      @Bean     public LinkDiscoverers discoverers() {         List<LinkDiscoverer> plugins = new ArrayList<>();         plugins.add(new CollectionJsonLinkDiscoverer());         return new LinkDiscoverers(SimplePluginRegistry.create(plugins));      } } 
like image 67
dukevin Avatar answered Sep 29 '22 01:09

dukevin


For me this link helped: https://github.com/spring-projects/spring-hateoas/issues/731

In a nutshell i added to my dependencies:

<dependency>     <groupId>org.springframework.plugin</groupId>     <artifactId>spring-plugin-core</artifactId>     <version>2.0.0.RELEASE</version> </dependency> 
like image 29
Alexander Weiß Avatar answered Sep 29 '22 01:09

Alexander Weiß