【问题标题】:Spring WebFlux application running tomcat instead of NettySpring WebFlux 应用程序运行 tomcat 而不是 Netty
【发布时间】:2020-08-05 08:12:17
【问题描述】:

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

所以我想通过运行 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>

【问题讨论】:

  • 使用mvn dependency:tree(或Eclipse POM 依赖查看器)找出它被拉入的位置。

标签: java spring-boot netty spring-webflux


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    Springfox 2.9.2 版不支持 webflux。

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

    您可以在此处阅读有关它的更多信息。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-31
      • 1970-01-01
      • 2012-05-27
      • 2018-09-19
      • 2018-03-31
      • 2018-10-22
      • 2019-12-07
      相关资源
      最近更新 更多