***************************
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.
报错原因
在导入spring gateway时会自动导入web的依赖,这与原来项目中的web依赖冲突了
解决方法
删除原来项目的依赖
对已经导入的,内嵌有web依赖的进行排除
将下面的排除依赖的代码放入指定位置,即可排除web依赖
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</exclusion>
</exclusions>
<dependency>
<groupId>自己写的依赖</groupId>
<artifactId>自己写的依赖</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</exclusion>
</exclusions>
</dependency>
注:经过测试,将排除依赖的代码放在spring gateway中去排除spring gateway的web,结果还是报错。