Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency.

关于spring-mvc和springcloud依赖冲突问题

网上很多都没有说清楚,大部分就是让我们移除spring-boot-starter-web依赖。

先说结论,导致冲突问题的根本原因是spring-webmvc

Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency._第1张图片
但是我并没有这个依赖。

我们从源码的角度来看为什么会出现报错。

logback一定要设置成debug模式,info是看不到报错信息的

org.springframework.cloud.gateway.support.MvcFoundOnClasspathException: null
Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency._第2张图片
我们定位到这个类

Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency._第3张图片
可以看到,冲突的原因是因为ioc容器中已经有了DispatcherHandler。所以,我们只需要移除他所在的包即可。

DispatcherServlet在spring-webmvc中,因此,虽然没有spring-boot-starter-web依赖,但是也会同样的报错

Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency._第4张图片

你可能感兴趣的:(spring,java)