使用 Spring 带有嵌入式 Tomcat 的引导 Webflux
Using Spring Boot Weblfux with embedded Tomcat
我正在尝试在新的 Spring 引导应用程序中使用 WebFlux 反应类型。我在 https://start.spring.io 使用了 initializr 并选择了 2.0.0-SNAPSHOT 版本。我添加了网络响应依赖项,我所做的一切都很好。这是一个非常可靠的 POC,目标是如何利用这些类型来使我们的 API 现代化,为此,我们计划慢慢替换阻塞 and/or 同步进程的每个部分,并将其替换为非阻塞替代实施。
我遇到的问题是,当我尝试将我的 POC 发展成更类似于我们在生产中拥有的服务时,很多事情似乎都不起作用。现在我明白 webflux 还不是 GA,我不应该期待所有其他 spring 项目的完全反应支持。但是我确实记得当 webflux 仍然被称为 web-reactive 时你可以 运行 on undertow/jetty/netty/tomcat/etc 但现在我正在使用 webflux 启动器,一切都默认为 netty,我没有看到文档调用了解如何将其更改为我们其他服务当前正在使用的嵌入式 tomcat。
是否仍然可以将 spring-boot-starter-webflux 与其他应用程序容器一起使用,或者我现在是否需要手动 bootstrap webflux 才能使用 netty 以外的东西?
您可以从 spring-boot-starter-webflux
依赖项中排除 spring-boot-starter-reactor-netty
并改用 spring-boot-starter-tomcat
、spring-boot-starter-undertow
或 spring-boot-starter-jetty
。
如果你的objective是使用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>
我正在尝试在新的 Spring 引导应用程序中使用 WebFlux 反应类型。我在 https://start.spring.io 使用了 initializr 并选择了 2.0.0-SNAPSHOT 版本。我添加了网络响应依赖项,我所做的一切都很好。这是一个非常可靠的 POC,目标是如何利用这些类型来使我们的 API 现代化,为此,我们计划慢慢替换阻塞 and/or 同步进程的每个部分,并将其替换为非阻塞替代实施。
我遇到的问题是,当我尝试将我的 POC 发展成更类似于我们在生产中拥有的服务时,很多事情似乎都不起作用。现在我明白 webflux 还不是 GA,我不应该期待所有其他 spring 项目的完全反应支持。但是我确实记得当 webflux 仍然被称为 web-reactive 时你可以 运行 on undertow/jetty/netty/tomcat/etc 但现在我正在使用 webflux 启动器,一切都默认为 netty,我没有看到文档调用了解如何将其更改为我们其他服务当前正在使用的嵌入式 tomcat。
是否仍然可以将 spring-boot-starter-webflux 与其他应用程序容器一起使用,或者我现在是否需要手动 bootstrap webflux 才能使用 netty 以外的东西?
您可以从 spring-boot-starter-webflux
依赖项中排除 spring-boot-starter-reactor-netty
并改用 spring-boot-starter-tomcat
、spring-boot-starter-undertow
或 spring-boot-starter-jetty
。
如果你的objective是使用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>