Consider defining a bean of type ‘org.springframework.http.codec.ServerCodecConfigurer‘ in your conf

本文介绍了解决Spring Cloud Gateway启动时报错的方法。错误源于Spring Cloud Gateway与Spring MVC之间的依赖冲突。文章提供了两种解决方案:一是移除SpringMVC模块;二是通过exclusion配置排除spring-boot-starter-web依赖。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

启动报错

Description:

Parameter 0 of method modifyRequestBodyGatewayFilterFactory in org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' in your configuration.

 

Spring Cloud Gateway 基于WebFlux(底层是采用Reactive Netty的NIO框架)框架实现的,与传统的SpringMvc分属两大体系,所以之间存在依赖冲突,我们只需要把SpringMvc模块使用exclusion移除掉即可。

 在类路径上找到的Spring MVC,此时它与Spring Cloud网关不兼容。请删除spring-boot-start-web依赖项。

因为spring cloud gateway是基于webflux的,如果非要web支持的话需要导入spring-boot-starter-webflux而不是spring-boot-start-web。

注意有两种情况:

1、自身Moudle添加了spring-boot-start-web则直接删除即可

2、自身Moudle没有添加spring-boot-start-web,也没有继承Moudle,但是还是出现上面的错误,那就具体看看是不是继承了父Moudle下面的某个子Moudle,如果是也会将spring-boot-start-web继承过来的。

  如果继承子Moudle,就用此方法进行排除   
      <dependency>
            <groupId>com.slin.stu</groupId>
            <artifactId>service-api</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值