错误详情
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-11-28 09:26:11.105 ERROR 19816 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
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.
错误分析
网关异常出现Consider defining a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' in your configuration.
要排除其他依赖的spring-boot-starter-web
以及spring-boot-starter-webflux
,因为会与spring-boot-starter-gateway
的webflux
冲突
错误解决
将原本的gateway依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
修改为
<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>
</exclusions>
</dependency>
刷新pom.xml文件后,再次运行项目
修改前:
修改后:
问题解决
峰回路转
按照上面的操作去做,问题确实是解决了,运行也没有问题了,但是网关作用失效了
运行成功的上面,还是提示了
访问网关(网关配置正常)
访问结果,404
博主在此纠结了两天,一直以为是网关配置错误的原因,后面尝试着用了下面的方法,最终解决问题,也发现了前面方法的问题,是网关失效了(与配置文件无关,是环境的问题)
解决方法
由于spring-boot-starter-web依赖产生的问题,所以我们找到这个依赖是如何进入我们当前的模块的,只有两种方式:1.从父项目中继承;2.自身添加
- 首先检查本模块的pom.xml文件中有没有添加web依赖,若有,删除该依赖
- 找到父项目的pom.xml文件,查看是否有web依赖,若有,则删除该依赖,同时在其他需要web依赖的子项目中加上该依赖
- 由于web依赖已经被删除,此时需要将gateway依赖中的
<exclusions>
标签整体删除
- 刷新pom.xml文件夹
完成上述步骤后,重启gateway对应的子模块
此时,发现运行成功的上面已经没有了WARN提示
其他都不用改,访问之前访问失败的地址
发现访问成功,这也证明了,是环境的问题,不是我们配置的网关有问题
至此,问题真正解决
更多推荐
SpringCloud配置网关时运行项目出现Consider defining a bean of type ‘org.springframework.http
发布评论