Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please

  畅购商城使用gateway任务中,启动GatewayWebApplication报如下错误:

Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.

  首先确保自己的application.yml配置文件没有错误。

问题原因:Gateway 不支持spring boot web包

解决方法:在gateway项目pom依赖中使用标签<exclusion去除spring-boot-starter-web依赖。
在这里插入图片描述
  有博客说还要移除springmvc和springwebflux依赖,然后再添加指定版本的springwebflux依赖,我最终成功后试了后其实不需要。可能的原因还是父工程会引入spring-boot-starter-web依赖,此时可以点击File->Project Structure移除相关的spring-boot-starter-web依赖,然后再启动工程。
在这里插入图片描述
gateway工程的完整依赖信息:

<dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</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>-->
                <exclusion>
                    <groupId>org.apache.tomcat.embed</groupId>
                    <artifactId>tomcat-embed-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
            <version>2.1.4.RELEASE</version>
        </dependency>-->
        <!--<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.1.2.RELEASE</version>
        </dependency>-->

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

题外:此外,本人由于不小心从父工程引入的依赖和子工程指定的依赖存在版本不一致,还会有版本冲突问题。对于这些问题,只能耐心多参考一些博客,分析依赖的版本信息,移除对应的冲突依赖。

另外一篇博客问题也是类似的,要注意子工程会从父工程引入依赖。

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值