Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway.

报错信息

powershell 复制代码
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.

解析

这个错误信息是因为你的项目中同时存在Spring MVC和Spring Cloud Gateway,这两者是不兼容的。

Spring Cloud Gateway是基于Spring WebFlux构建的,Spring WebFlux是一个非阻塞的反应式web框架,而Spring MVC是一个阻塞的框架,它包含在spring-boot-starter-web依赖中。 要解决这个问题,你需要做以下其中一项:

①:如果不需要,从你的pom.xml中移除spring-boot-starter-web依赖。

②:如果你在同一个应用中需要Spring MVC和Spring Cloud Gateway,你可以在你的application.yml或application.properties文件中将web应用类型设置为REACTIVE。

以下是如何在application.yml中将web应用类型设置为REACTIVE:

yaml 复制代码
spring:
  main:
    web-application-type: reactive
相关推荐
十月南城4 小时前
Spring Cloud生态地图——注册、配置、网关、负载均衡与可观测的组合拳
spring·spring cloud·负载均衡
没有bug.的程序员4 小时前
服务安全:内部服务如何防止“裸奔”?
java·网络安全·云原生安全·服务安全·零信任架构·微服务安全·内部鉴权
一线大码5 小时前
SpringBoot 3 和 4 的版本新特性和升级要点
java·spring boot·后端
weixin_440730505 小时前
java数组整理笔记
java·开发语言·笔记
weixin_425023005 小时前
Spring Boot 实用核心技巧汇总:日期格式化、线程管控、MCP服务、AOP进阶等
java·spring boot·后端
一线大码5 小时前
Java 8-25 各个版本新特性总结
java·后端
2501_906150565 小时前
私有部署问卷系统操作实战记录-DWSurvey
java·运维·服务器·spring·开源
better_liang6 小时前
每日Java面试场景题知识点之-TCP/IP协议栈与Socket编程
java·tcp/ip·计算机网络·网络编程·socket·面试题
niucloud-admin6 小时前
java服务端——controller控制器
java·开发语言
To Be Clean Coder6 小时前
【Spring源码】通过 Bean 工厂获取 Bean 的过程
java·后端·spring