我试图在新的Spring Boot App中使用WebFlux反应类型。我在https://start.spring.io使用了initializr并选择了2.0.0-SNAPSHOT版本。我添加了Web反应依赖,我所做的一切都很棒。这是一个非常可靠的POC,目标是如何利用这些类型来实现API的现代化,为此,我们计划慢慢替换阻塞和/或同步过程的每个部分,并将其替换为非阻塞的替代实现。
我遇到的问题是,当我试图将我的POC发展成更类似于我们在生产中所拥有的服务的东西时,很多东西似乎都不起作用。现在我知道webflux尚未成为GA,而且我不应该期待所有其他春季项目的完全反应性支持。但是我记得当webflux仍然被称为web-reactive,你可以在underow / jetty / netty / tomcat / etc上运行但是现在我正在使用webflux启动器,一切都默认为netty,我也没有看到docs调用如何将其更改为我们其他服务当前正在使用的嵌入式tomcat。
是否仍然可以将spring-boot-starter-webflux与其他应用程序容器一起使用,或者我现在是否需要手动引导webflux以使用除netty之外的其他东西?
答案 0 :(得分:6)
您可以从spring-boot-starter-reactor-netty
依赖项中排除spring-boot-starter-webflux
,然后使用spring-boot-starter-tomcat
,spring-boot-starter-undertow
或spring-boot-starter-jetty
。
答案 1 :(得分: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>