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)。

 

问题原因

  1. ​​依赖冲突​​:项目同时引入了:

    • spring-cloud-starter-gateway(需要响应式Web)
    • spring-boot-starter-web(基于Servlet的阻塞式Web)
  2. ​​框架不兼容​​:

    • Spring Cloud Gateway 基于 ​​Reactive WebFlux​​(非阻塞IO)
    • Spring MVC 基于 ​​Servlet API​​(阻塞IO)
    • 两者不能共存
posted @ 2025-06-11 15:22  joshua317  阅读(270)  评论(0)    收藏  举报