使用 spring 反应配置 Swagger-ui 时出错

Getting error while configuring Swagger-ui with spring reactive

在将 swagger-ui 与使用 JHipster 7.1.0 为 Java 11 生成的反应式 spring 项目集成时。我添加了以下依赖项。

应用程序具有以下 swagger 依赖项

POM 依赖项

<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-common</artifactId>
  <version>1.4.3</version>
</dependency>
<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-webflux-core</artifactId>
  <version>1.4.3</version>
</dependency>
<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-webflux-ui</artifactId>
  <version>1.4.3</version>
</dependency>

除此之外我们添加了一个配置SwaggerConfig.java

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.parameters.Parameter;
import org.springdoc.core.GroupedOpenApi;
import org.springdoc.core.customizers.OpenApiCustomiser;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@OpenAPIDefinition(info = @Info(title = "Amazingbabbage", version = "1.0", description = "Documentation APIs v1.0"))
public class SwaggerConfig {
    @Bean
    public GroupedOpenApi employeeGroupApi() {
        return GroupedOpenApi.builder()
                .group("all")
                .pathsToMatch("/api/**")
                .build();
    }

    public OpenApiCustomiser getOpenApiCustomiser() {

        return openAPI -> openAPI.getPaths().values().stream().flatMap(pathItem ->
                        pathItem.readOperations().stream())
                .forEach(operation -> {
                    operation.addParametersItem(new Parameter().name("Authorization").in("header").
                            schema(new StringSchema().example("token")).required(true));
                    operation.addParametersItem(new Parameter().name("userId").in("header").
                            schema(new StringSchema().example("test")).required(true));

                });
    }
}

{
  "type" : "https://www.jhipster.tech/problem/problem-with-message",
  "title" : "Internal Server Error",
  "status" : 500,
  "detail" : "No primary or single public constructor found for interface org.springframework.http.server.reactive.ServerHttpRequest - and no default constructor found either",
  "path" : "/swagger-doc/swagger-ui.html",
  "message" : "error.http.500"
}

如果您遇到类似问题,请分享您的反馈或意见。

当您同时存在 Spring MVC 和 Webflux 时,Spring Boot 将配置您的应用程序以仅使用 Spring MVC。 (参见:https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.spring-application.web-environment

您需要确保 Spring MVC 依赖项不存在于您的项目中。