Spring MVC和Spring Cloud Gateway二者不能同时用
ERROR 56008 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway. Action: Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency. Process finished with exit code 0
根据错误信息,问题在于同时引入了Spring MVC(通常是spring-boot-starter-web)和Spring Cloud Gateway,它们是不兼容的。因为Spring Cloud Gateway基于WebFlux(响应式编程模型),而spring-boot-starter-web使用的是Servlet模型(Spring MVC)。
问题原因
-
依赖冲突:项目同时引入了:
spring-cloud-starter-gateway(需要响应式Web)spring-boot-starter-web(基于Servlet的阻塞式Web)
-
框架不兼容:
- Spring Cloud Gateway 基于 Reactive WebFlux(非阻塞IO)
- Spring MVC 基于 Servlet API(阻塞IO)
- 两者不能共存

浙公网安备 33010602011771号