springboot gateway 项目报org.springframework.http.codec.ServerCodecConfigurer

在Spring Cloud Gateway项目中遇到启动失败的问题,原因是`spring-boot-starter-web`与Gateway的`webflux`冲突。解决方案是检查并移除项目中引入的`spring-boot-starter-web`依赖,或者单独管理子模块的`pom.xml`,避免继承父模块中的web依赖。同时提到了Hystrix熔断处理和web依赖的问题。
部署运行你感兴趣的模型镜像

标题由于字数限制,写不了这么多字……

完整异常信息:

***************************
APPLICATION FAILED TO START
***************************

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.

不浪费大家时间:

出现这个问题是因为这俩冲突,如果要用gateway的话,得找找引入的依赖里面有没有引入spring-boot-starter-web,然后剔除掉

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>

 

有时间的再看下面吧

原理:

官网:https://docs.spring.io/spring-cloud-gateway/docs/2.2.8.RELEASE/reference/html/#gateway-how-it-works

资料:https://my.oschina.net/uwith/blog/3063340https://blog.youkuaiyun.com/jamesleel/article/details/84838057

结合官网和网络上资料,Spring Cloud Gateway 是使用 netty+webflux实现,webflux与web是冲突的。

但是这个web说的是spring-boot-starter-web !!!

解决方案:(网上其他的就不说了,找找就知道了,都差不多的,极其类似

我提供下我出险这个问题的原因和解决思路:

刚开始我的项目目录

parent

    |-----gateway

                |-----pom.xml

    |-----pom.xml

gateway项目是一个模块,刚开始引用了parent的pom,在parent的pom中存在web依赖

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>

解决思路:

还是按照结论(webflux与spring-boot-starter-web是冲突的)去找

1,把gateway项目不引用parent的pom,完全自己管理pom

2,在当前项目内找哪些包里引用了web的包,如果有,看能否删除

 

根据这个思路,找到了zuul包中引入了web的包,只要去除这个zuul依赖就能正常启动了

去除之后:

 

在当前项目内引入了Hystrix作为熔断降级处理,需要一个访问失败之后的回调方法

在这个方法内部使用了web的RestController和RequestMapping,这个web是spring-web,和上面是俩回事

 

 

 

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值