标题由于字数限制,写不了这么多字……
完整异常信息:
***************************
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/3063340,https://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,和上面是俩回事



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





