草庐IT

关于 java:为什么 HATEOAS 在使用 Swagger 2.x 启动期间开始为 spring-boot 版本> = 2.2.x 创建问题?

codeneng 2023-03-28 原文

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

我将我的项目从 spring-boot 2.1.9 移动到 2.2.0。

在启动项目时,我面临以下 error 消息。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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]

是什么导致了这个问题?

注意:我没有在我的 pom.xml 文件中使用 HATEOAS。

pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<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>
    0.8.1</assertj-swagger>
    <jacoco-version>0.8.4</jacoco-version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        spring-boot-configuration-processor</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        springfox-swagger2</artifactId>
        <version>${swagger-springfox.version}</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        springfox-swagger-ui</artifactId>
        <version>${swagger-springfox.version}</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        springfox-spring-web</artifactId>
        <version>${swagger-springfox.version}</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        springfox-core</artifactId>
        <version>${swagger-springfox.version}</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        springfox-data-rest</artifactId>
        <version>${swagger-springfox.version}</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        springfox-bean-validators</artifactId>
        <version>${swagger-springfox.version}</version>
    </dependency>

  • 使用 mvn dependency:tree 并检查是否有其他东西正在拉入 Hateoas 依赖项。 IRC 如果您使用依赖于 Spring Hateoas 的 Spring Data REST。
  • 我在升级时遇到了同样的问题。我确实知道依赖项来自何处,但我一直无法找到解决方案。
  • 您能否在这里指导我:stackoverflow.com/questions/60001241/...?


我的 spring-boot 应用程序中的 Swagger + HATEOAS 遇到了这个问题。

下面给出了修复(编辑你的 Swagger 配置类):

1
2
3
4
5
6
7
8
9
10
11
12
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

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

    }
}

  • 这似乎对我不起作用,因为在响应中 _links 变成了 links 并且 _embedded 变成了 content ,因此我检查 _links 的大多数 mvcMock 测试都失败了,API与 spring-boot-starter-hateos 开箱即用的内容不同
  • 我也发生过这种情况。您需要启用 Hal json
  • 柠檬你能详细说明一下吗?我尝试使用 HalLinkDiscoverer 类而不是 CollectionJsonLinkDiscoverer 没有做到这一点,但我的测试仍然失败,因为链接呈现为 links 而不是 _links,并且内容是呈现为 content 而不是预期的 _embedded
  • 我在配置 java 文件中这样做的方式是 @EnableHypermediaSupport(type=EnableHypermediaSupport.Hyperm??ediaType.HAL),您必须包含 org.springframework.hateoas.config.EnableHypermediaSupport。不确定它是否重要,但我有一个依赖项:spring-boot-starter-hateoas
  • @lemon 不错的答案!这适用于 spring-boot 2.3.0 hatoas Swagger 2.9.2
  • 这个解决方案对我有用..但我很想知道这在逻辑上到底在做什么?有问题吗?它是如何修复的?
  • @lemon 这拯救了我的一天。谢谢。你能描述一下它到底是做什么的吗?
  • @Kerruba 你能解决这个问题吗?我也面临同样的问题。
  • @lemon 您的回复解决了我的问题,但在添加 EnableHypermediaSupport(type=EnableHypermediaSupport.Hyperme??diaType.HAL) 后,同样的问题又开始出现了。我尝试了这个,因为作为回应,我得到的是 links 而不是 _links
  • SimplePluginRegistry.create() 似乎已被弃用。有没有替代方案?


对我来说这个链接有帮助:https://github.com/spring-projects/spring-hateoas/issues/731

简而言之,我添加了我的依赖项:

1
2
3
4
5
<dependency>
    <groupId>org.springframework.plugin</groupId>
    spring-plugin-core</artifactId>
    <version>2.0.0.RELEASE</version>
</dependency>

  • 谢谢!这对我有用。此外,在本教程中,还有对该依赖项的引用:baeldung.com/spring-hateoas-tutorial


此类问题是由于 Hateoas 的一项新功能而发生的。

如果你想解决这个问题,只需在你的swagger配置文件中嵌入下面这行代码即可。

1
2
3
4
5
6
7
@Primary
@Bean
public LinkDiscoverers discoverers() {
    List<LinkDiscoverer> plugins = new ArrayList<>();
    plugins.add(new CollectionJsonLinkDiscoverer());
    return new LinkDiscoverers(SimplePluginRegistry.create(plugins));
}

我认为这会解决你的问题,因为它解决了我的问题。


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    Use following 2 dependency to resolve Swagger and Hateoas dependency conflict.
   
    If Spring Boot version is >= 2.2.0 the use io.springfox version 3.0.0
   
    <dependency>
        <groupId>io.springfox</groupId>
        springfox-swagger2</artifactId>
        <version>3.0.0</version>
    </dependency>
   
    <dependency>
        <groupId>io.springfox</groupId>
        springfox-swagger-ui</artifactId>
        <version>3.0.0</version>
    </dependency>

使用 3.0.0 版本后,swagger-ui 将无法工作,因此请使用以下依赖项和用户 /swagger-ui/ 而不是 /swagger-ui.html

1
2
3
4
5
    <dependency>
        <groupId>io.springfox</groupId>
        springfox-boot-starter</artifactId>
        <version>3.0.0</version>
    </dependency>

  • 为了解决我的问题,我首先要做@lemon 描述的事情,然后将 Springfox 依赖项升级到 3.0.0 并添加启动器。如果没有这个,我会多次出现可用的 bean,而 Spring Boot 无法选择。


我使用

时遇到的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
<dependency>
   <groupId>org.springframework.boot</groupId>
   spring-boot-dependencies</artifactId>
   <version>2.2.6.RELEASE</version>
   <type>pom</type>
   <scope>import</scope>
</dependency>
.....
.....
<dependency>
  <groupId>org.springframework.boot</groupId>
  spring-boot-starter-hateoas</artifactId>
</dependency>

用springfox招摇

1
2
3
4
5
6
7
8
9
10
<dependency>
  <groupId>io.springfox</groupId>
  springfox-swagger2</artifactId>
  <version>2.9.2</version>
</dependency>
<dependency>
  <groupId>io.springfox</groupId>
  springfox-swagger-ui</artifactId>
  <version>2.9.2</version>
</dependency>

如果您查看 spring hateoas 依赖项,则存在对 spring-plugin-core 版本 2.0.0.RELEASE

的依赖项

1
2
3
4
5
<dependency>
    <groupId>org.springframework.plugin</groupId>
    spring-plugin-core</artifactId>
    <version>${spring-plugin.version}</version>
</dependency>

但是大张旗鼓的依赖使用 spring-plugin-core 和版本 1.2.0.RELEASE.

spring-boot创建bean有冲突,需要统一org.springframework.plugin版本让spring看到,如果选择2.0.0.RELEASEswagger就可以编译,

所以版本 1.2.0.RELEASE 将适用于两个依赖项,例如

1
2
3
4
5
 <dependency>
    <groupId>org.springframework.plugin</groupId>
    spring-plugin-core</artifactId>
    <version>1.2.0.RELEASE</version>
</dependency>

之后,您需要配置类来为 SwaggerHATEOAS 启动 bean,如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@EnableSwagger2
@Configuration
public class SwaggerConfiguration {

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

    @Bean
    public Docket postsApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("{ApplicationName}")
                .apiInfo(buildApiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.regex("/.*"))
                .build();
    }

    private ApiInfo buildApiInfo() {
        Contact contact = new Contact("CompanyName","https://company-domain.com","mail@company.com");
        return new ApiInfoBuilder()
                .title(""{ApplicationName}"")
                .description("API Description")
                .license("license")
                .version("1.0")
                .contact(contact)
                .licenseUrl("licenseURl")
                .build();
    }
}

  • 谢谢!这个解决方案对我有用,我使用 @EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL) 来让 "_links" 带有下划线。我将 swagger 版本更新为 2.9.2。但是,我不需要 discovers() 方法,它仍然有效!


对于 Spring boot 版本 2.1.3.RELEASE 用户,以下依赖项适用于 hatoas swagger:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
    <dependency>
        <groupId>org.springframework.boot</groupId>
        spring-boot-starter-hateoas</artifactId>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        springfox-swagger2</artifactId>
        <version>2.9.2</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        springfox-swagger-ui</artifactId>
        <version>2.9.2</version>
    </dependency>

试试这个2.6.1版本,我已经用这个方法解决了

1
2
3
4
5
6
7
8
9
10
<dependency>
    <groupId>io.springfox</groupId>
    springfox-swagger2</artifactId>
    <version>2.6.1</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    springfox-swagger-ui</artifactId>
    <version>2.6.1</version>
</dependency>

  • 这对我来说也没有任何改变。


我正在使用 springdoc-openapi,在遇到类似于这里提到的问题后:

1
2
3
4
5
6
7
8
9
10
11
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

我只是在我的 pom 文件中添加了这个依赖

1
2
3
4
5
<dependency>
    <groupId>org.springframework.hateoas</groupId>
    spring-hateoas</artifactId>
    <version>1.1.1.RELEASE</version>
</dependency>

希望这可以帮助某人


最佳解决方案

在 SwaggerConfig 类中添加以下代码

1
2
3
4
5
6
@Bean
public LinkDiscoverers discovers() {    
    List<LinkDiscoverer> plugins = new ArrayList<>();
    plugins.add(new CollectionJsonLinkDiscoverer());
    return new LinkDiscoverers(SimplePluginRegistry.create(plugins));[enter image description here][1]  
}

作为亚历山大·魏?已经回答,spring-plugin-core 依赖解决了错误的版本 1.2.0.RELEASE.

为了强制使用正确的2.0.0.RELEASE,你必须要么排除错误的传递依赖并明确指定正确的,要么在pom.xml中固定(!)那个依赖版本。这是在 <dependenciesManagement> 块中完成的,而不是在 <dependencies> 块中。 Springfox 3.0.0 的固定示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<properties>
    <spring-plugin-core.version>2.0.0.RELEASE</spring-plugin-core.version>
    <springfox.version>3.0.0</springfox.version>
</properties>

<dependencyManagement>
  <dependencies>
    <!-- API Documentation -->
    <!-- Fix wrong resolved `spring-plugin-core` dependency version for springfox -->
    <dependency>
      <groupId>org.springframework.plugin</groupId>
      spring-plugin-core</artifactId>
      <version>${spring-plugin-core.version}</version>
    </dependency>
    <dependency>
      <groupId>io.springfox</groupId>
      springfox-boot-starter</artifactId>
      <version>${springfox.version}</version>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <!-- API Documentation -->
  <dependency>
    <groupId>io.springfox</groupId>
    springfox-boot-starter</artifactId>
  </dependency>
</dependencies>

我收到错误

"在类路径资源 [org/springframework/hateoas/mediatype/hal/HalMediaTypeConfiguration.class] 中定义名称为 'halLinkDisocoverer' 的 bean 创建错误"..

在构建超媒体驱动的 RESTful Web 服务时

删除这个依赖

1
2
3
4
5
<dependency>
     <groupId>com.jayway.jsonpath</groupId>
     json-path</artifactId>
     <scope>test</scope>
</dependency>

解决了我的问题。

查看此链接了解更多详情
为什么我收到错误工厂方法"halLinkDisocoverer"在 springboot 中引发异常?


您可以像这样更改版本:

1
2
3
4
5
6
7
8
9
10
<dependency>
    <groupId>io.springfox</groupId>
    springfox-swagger2</artifactId>
    <version>3.0.0</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    springfox-swagger-ui</artifactId>
    <version>2.8.0</version>
</dependency>

我正在使用 Spring Boot 2.4.1。但是在启动 Spring Boot 应用程序时看不到 Swagger 端点日志。


所以我实际上想要 hatoas 支持并且遇到了同样的问题。如果你有

就会发生这种情况

1
2
3
4
<dependency>
  <groupId>org.springframework.hateoas</groupId>
  spring-hateoas</artifactId>
</dependency>

而不是

1
2
3
4
<dependency>
  <groupId>org.springframework.boot</groupId>
  spring-boot-starter-hateoas</artifactId>
</dependency>

  • 还想指出当前与 hatoas swagger spring boot 2.2.0 不兼容。您可以运行 hatoas 或 swagger,但不能同时运行。 github.com/springfox/springfox/issues/2932
  • 我没有使用hateoas,也不需要它。我什至尝试从 spring web starter 中排除 hatoas 依赖。


已解决,当 Swagger HATEOAS 与 Spring Boot 2.2.4.RELEASE 一起使用时,由于集成而发生此问题。RELEASE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.company.springbootworks.swagger;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.hateoas.client.LinkDiscoverer;
import org.springframework.hateoas.client.LinkDiscoverers;
import org.springframework.hateoas.mediatype.collectionjson.CollectionJsonLinkDiscoverer;
import org.springframework.http.ResponseEntity;
import org.springframework.plugin.core.SimplePluginRegistry;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.DocExpansion;
import springfox.documentation.swagger.web.ModelRendering;
import springfox.documentation.swagger.web.OperationsSorter;
import springfox.documentation.swagger.web.TagsSorter;
import springfox.documentation.swagger.web.UiConfiguration;
import springfox.documentation.swagger.web.UiConfigurationBuilder;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

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

    }

    @Bean
    public Docket eDesignApi(SwaggerConfigProperties swaggerConfigProperties) {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo(swaggerConfigProperties))
                .enable(Boolean.valueOf(swaggerConfigProperties.getEnabled())).select()
                .apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build().pathMapping("/")
                .directModelSubstitute(LocalDate.class, String.class).genericModelSubstitutes(ResponseEntity.class)
                .useDefaultResponseMessages(Boolean.valueOf(swaggerConfigProperties.getUseDefaultResponseMessages()))
                .enableUrlTemplating(Boolean.valueOf(swaggerConfigProperties.getEnableUrlTemplating()));
    }

    @Bean
    UiConfiguration uiConfig(SwaggerConfigProperties swaggerConfigProperties) {
        return UiConfigurationBuilder.builder().deepLinking(Boolean.valueOf(swaggerConfigProperties.getDeepLinking()))
                .displayOperationId(Boolean.valueOf(swaggerConfigProperties.getDisplayOperationId()))
                .defaultModelsExpandDepth(Integer.valueOf(swaggerConfigProperties.getDefaultModelsExpandDepth()))
                .defaultModelExpandDepth(Integer.valueOf(swaggerConfigProperties.getDefaultModelExpandDepth()))
                .defaultModelRendering(ModelRendering.EXAMPLE)
                .displayRequestDuration(Boolean.valueOf(swaggerConfigProperties.getDisplayRequestDuration()))
                .docExpansion(DocExpansion.NONE).filter(Boolean.valueOf(swaggerConfigProperties.getFilter()))
                .maxDisplayedTags(Integer.valueOf(swaggerConfigProperties.getMaxDisplayedTags()))
                .operationsSorter(OperationsSorter.ALPHA)
                .showExtensions(Boolean.valueOf(swaggerConfigProperties.getShowExtensions()))
                .tagsSorter(TagsSorter.ALPHA).supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS)
                .validatorUrl(null).build();
    }

    private ApiInfo apiInfo(SwaggerConfigProperties swaggerConfigProperties) {
        return new ApiInfoBuilder().title(swaggerConfigProperties.getTitle())
                .description(swaggerConfigProperties.getDescription()).version(swaggerConfigProperties.getApiVersion())
                .build();
    }
}

及以下是swagger依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<properties>
    <java.version>1.8</java.version>
    <swagger.version>2.9.2</swagger.version>
    <swagger-annotations.version>1.5.21</swagger-annotations.version>
    <swagger-models.version>1.5.21</swagger-models.version>
    <spring-plugin.version>2.0.0.BUILD-SNAPSHOT</spring-plugin.version>
</properties>


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

  • 您从哪里获得 SwaggerConfigProperties ?


我已经删除了这些依赖项作为解决方法并工作了:

1
2
3
4
5
6
7
8
9
10
11
<dependency>
    <groupId>io.springfox</groupId>
    springfox-swagger2</artifactId>
    <version>2.4.0</version>
</dependency>

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

如果对你有用,请告诉我。


如果你想要 Swagger,但可以与 HATEOAS 妥协,那么只需删除 HATEOAS 依赖项并添加:

1
2
compile group: 'io.springfox', name: 'springfox-swagger-ui', version:'2.9.2'  
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'

有关关于 java:为什么 HATEOAS 在使用 Swagger 2.x 启动期间开始为 spring-boot 版本> = 2.2.x 创建问题?的更多相关文章

  1. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  2. ruby-on-rails - Rails - 子类化模型的设计模式是什么? - 2

    我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co

  3. ruby - 在 64 位 Snow Leopard 上使用 rvm、postgres 9.0、ruby 1.9.2-p136 安装 pg gem 时出现问题 - 2

    我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po

  4. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  5. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  6. ruby - 通过 rvm 升级 ruby​​gems 的问题 - 2

    尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub

  7. ruby - 为什么 4.1%2 使用 Ruby 返回 0.0999999999999996?但是 4.2%2==0.2 - 2

    为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返

  8. ruby - ruby 中的 TOPLEVEL_BINDING 是什么? - 2

    它不等于主线程的binding,这个toplevel作用域是什么?此作用域与主线程中的binding有何不同?>ruby-e'putsTOPLEVEL_BINDING===binding'false 最佳答案 事实是,TOPLEVEL_BINDING始终引用Binding的预定义全局实例,而Kernel#binding创建的新实例>Binding每次封装当前执行上下文。在顶层,它们都包含相同的绑定(bind),但它们不是同一个对象,您无法使用==或===测试它们的绑定(bind)相等性。putsTOPLEVEL_BINDINGput

  9. ruby - 通过 RVM (OSX Mountain Lion) 安装 Ruby 2.0.0-p247 时遇到问题 - 2

    我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search

  10. ruby-on-rails - 项目升级后 Pow 不会更改 ruby​​ 版本 - 2

    我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby​​版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby​​版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘

随机推荐