【问题标题】:Using Spring Boot Weblfux with embedded Tomcat使用带有嵌入式 Tomcat 的 Spring Boot Weblfux
【发布时间】:2017-09-14 06:54:32
【问题描述】:

我正在尝试在新的 Spring Boot 应用程序中使用 WebFlux 反应类型。我在https://start.spring.io 使用了initializr 并选择了2.0.0-SNAPSHOT 版本。我添加了 web 响应式依赖,我所做的一切都很好。这是一个非常可靠的 POC,目标是如何利用这些类型来现代化我们的 API,为此,我们计划慢慢替换阻塞和/或同步进程的每个部分,并用非阻塞替代实现替换它.

我遇到的问题是,当我尝试将我的 POC 发展为更类似于我们在生产中提供的服务时,许多事情似乎都不起作用。现在我知道 webflux 还不是 GA,我不应该期待所有其他 Spring 项目的完全响应式支持。然而,我确实记得当 webflux 仍然被称为 web-reactive 时,你可以在 undertow/jetty/netty/tomcat/etc 上运行,但现在我使用的是 webflux 启动器,一切都默认为 netty,我没有看到文档调用了解如何将其更改为我们其他服务当前正在使用的嵌入式 tomcat。

是否仍然可以将 spring-boot-starter-webflux 与其他应用程序容器一起使用,或者我现在是否需要手动引导 webflux 才能使用 netty 以外的其他东西?

【问题讨论】:

    标签: spring-boot spring-webflux


    【解决方案1】:

    您可以从 spring-boot-starter-webflux 依赖项中排除 spring-boot-starter-reactor-netty 并改用 spring-boot-starter-tomcatspring-boot-starter-undertowspring-boot-starter-jetty

    【讨论】:

    • 这仍然有效吗?我最终会缺少 Caused by: java.lang.NoClassDefFoundError: io/netty/buffer/Unpooled 这样的课程
    • 应该是。您能否使用完整的堆栈跟踪在 github.com/spring-projects/spring-boot/issues 上创建问题?
    • 那么 spring-boot-starter-reactor-netty 是否包含服务器? Netty 本身是服务器吗?从这里:stackoverflow.com/a/35749512/10894456我看到 Netty 不是服务器,还是我错了?
    • 是的,这个启动器附带一个客户端和一个服务器。 Netty 支持这两种情况。
    【解决方案2】:

    如果您的目标是使用 tomcat 服务器,则无需排除 spring-boot-starter-reactor-netty。添加spring boot starter tomcat会在Tomcat服务器中启动应用。

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
            <exclusions>
                <!-- Exclude the Netty dependency -->
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-reactor-netty</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- Use Tomcat instead -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
    

    【讨论】:

    • 如果我只想使用网络服务,为什么还要包含一个网络服务器?
    猜你喜欢
    • 1970-01-01
    • 2017-10-21
    • 2015-04-18
    • 1970-01-01
    • 2018-08-08
    • 2016-12-28
    • 2015-03-23
    • 2018-05-28
    • 2016-02-18
    相关资源
    最近更新 更多