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
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
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.
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.
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>
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]
}
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'