Spring WebFlux 应用 运行 tomcat 而不是 Netty

Spring WebFlux application running tomcat instead of Netty

我正在 运行 启动一个 spring 启动 WebFlux 应用程序,通常是在 Netty 嵌入式服务器之上的应用程序 运行。相反,我得到一个 tomcat 实例 运行ning,我试图从我的 pom 中排除 tomcat 但仍然遇到同样的问题。

所以我想通过 运行ning Netty 而不是 Tomcat 来解决这个问题。

这是我的 pom 依赖项:

<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct</artifactId>
    </dependency>

    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-processor</artifactId>
    </dependency>

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
    </dependency>

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-test</artifactId>
        <scope>test</scope>
    </dependency>

</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Springfox 2.9.2 版本不支持 webflux。

包含 webflux 支持的 Springfox 3.0.0 已作为快照提供,但很快就会发布。

您可以在此处阅读更多相关信息。

https://github.com/springfox/springfox/issues/2699

正如 Thomas 所说,springfox 不支持 webflux。

我建议使用 springDoc 提供的 OpenApi 实现,而不是 SpringFox,它仍然提供相同的 UI,使用 swagger 3 并且还支持 webflux。

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