Search code examples
spring-bootswaggerspring-webfluxspringdoc

Unable to display Swagger/OpenApi docs when using SpringDoc webflux support


I have a small Spring Boot micro-service that exposes its endpoint as reactive, using webflux.

When I run the application from IntelliJ, Gradle or from the cmd line with the SpringDoc webflux support:
implementation 'org.springdoc:springdoc-openapi-webflux-ui:1.4.4'
and I go to http://localhost:8080/swagger-ui.html I get a 500 error, the logs show:

java.lang.IllegalStateException: No primary or default constructor found for interface org.springframework.http.server.reactive.ServerHttpRequest]

and the root cause:

java.lang.NoSuchMethodException: org.springframework.http.server.reactive.ServerHttpRequest.<init>()

if I use http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config I get a 404 instead of a 500.

However if I change the dependency to the non reactive SpringDoc module:
implementation 'org.springdoc:springdoc-openapi-ui:1.4.4'

The docs are available, they just dont show return schema (I guess this is expected as the response is wrapped in a Mono).

I have looked at this question, but it didnt help

I am using Spring Boot 2.3.3.RELEASE, I have nothing "fancy" in the controller other than an autowired service class, the endpoint is simply annotated with the GetMapping and returns Mono<T>. and I have included the following dependencies:

    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springdoc:springdoc-openapi-webflux-ui:1.4.4'

Solution

  • Your project is using spring-boot-starter-web and spring-boot-starter-webflux.

    You just need to remove spring-boot-starter-web from your dependencies.