这是这样的,因为许多现有的Spring Boot Web应用程序(使用MVC)将依赖webflux启动器来使用WebClient. Spring MVC部分支持被动返回类型,因此这是一个预期的用例.相反的情况并非如此,因为反应性应用程序不太可能使用Spring MVC位.因此支持同时使用web和webflux启动器,但是它将配置Spring MVC应用程序.您始终可以通过以下方式强制Spring Boot应用程序进行反应: SpringApplication.setWebApplicationType(WebApplicationType.REACTIVE) 但是清理依赖关系仍然是一个好主意,因为在响应式Web应用程序中使用阻止功能很容易.When I start to learn the spring-webflux, I have the question about this component.I builded the simple project, useing the maven to manage the project, and add the dependences about spring-boot-starter-web and spring-boot-starter-webflux", like : <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>But it doesn't work. When removing the spring-boot-starter-web dependency, it can work well. 解决方案 As explained in the Spring Boot reference documentation section about WebFlux, adding both web and webflux starters will configure a Spring MVC web application.This is behaving like that, because many existing Spring Boot web applications (using MVC) will depend on the webflux starter to use the WebClient. Spring MVC partially support reactive return types, so this is an expected use case. The opposite isn't really true, since a reactive application is not really likely to use Spring MVC bits.So using both web and webflux starters is supported, but it will configure a Spring MVC application. You can always force the Spring Boot application to be reactive with:SpringApplication.setWebApplicationType(WebApplicationType.REACTIVE)But it's still a good idea to clean up dependencies as it would be easy to use a blocking feature in your reactive web application. 这篇关于spring-boot-starter-web和spring-boot-starter-webflux不一起工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 04:02
查看更多