Search code examples
spring-webfluxopenapiapi-docspringdoc-openapi-ui

OpenApi - required a bean of type 'org.springdoc.webmvc.ui.SwaggerIndexTransformer' that could not be found


I'm adding Swagger to my Spring Webflux service with functional controller. First I was getting this error:

Description: The bean 'swaggerWelcome', defined in class path resource [org/springdoc/webflux/ui/SwaggerConfig.class], could not be registered. A bean with that name has already been defined in class path resource [org/springdoc/webmvc/ui/SwaggerConfig.class] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

So I added spring.main.allow-bean-definition-overriding=true to my application.properties file.

And now I'm getting this error:

Description:

Parameter 1 of method swaggerWebMvcConfigurer in org.springdoc.webmvc.ui.SwaggerConfig required a bean of type 'org.springdoc.webmvc.ui.SwaggerIndexTransformer' that could not be found.

Action:

Consider defining a bean of type 'org.springdoc.webmvc.ui.SwaggerIndexTransformer' in your configuration.

Pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company/groupId>
    <artifactId>service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <!-- For all mvc and web functions -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>

        <!-- Default persistence functions -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-r2dbc</artifactId>
        </dependency>

        <dependency>
            <groupId>dev.miku</groupId>
            <artifactId>r2dbc-mysql</artifactId>
            <version>0.8.2.RELEASE</version>
            <scope>runtime</scope>
        </dependency>
        
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.5.9</version>
        </dependency>

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-webflux-ui</artifactId>
            <version>1.5.9</version>
        </dependency>

    </dependencies>
</project>

The application.properties file contains:

spring.main.allow-bean-definition-overriding=true

Is there a way to avoid this configuration? What is purpose the of the SwaggerIndexTransformer? Because in the website https://springdoc.org/#getting-started they say that "No additional configuration is needed".


Solution

  • The error was that in the pom file the only dependency should be springdoc-openapi-webflux-ui