gateway与spring-boot-starter-web冲突问题的解决


Posted in Java/Android onJuly 16, 2021

gateway与spring-boot-starter-web 冲突

环境:

SpringCloud 版本 ---- Finchley.SR2

SpringBoot 版本 ---- 2.0.6.RELEASE

问题描述:

将 zuul 网关升级为 gateway 时,引入gateway 依赖启动网关子项目报错

引入的依赖:

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

启动网关报错

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-12-31 10:26:35.211 ERROR 13124 --- [ 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.
Process finished with exit code 1

问题分析:

查看控制台打印日志:

gateway与spring-boot-starter-web冲突问题的解决

可以看到是 web 依赖下的 tomcat 容器启动失败,且打印出 nio 异常。

回顾一下 zuul 和 gateway 的区别

Zuul: 构建于 Servlet 2.5,兼容3.x,使用的是阻塞式的API,不支持长连接,比如 websockets。

Gateway构建于 Spring 5+,基于 Spring Boot 2.x 响应式的、非阻塞式的 API。同时,它支持 websockets,和 Spring 框架紧密集成

报错原因:启动时默认使用了 spring-boot-starter-web 的内置容器,不支持非阻塞

问题解决:

有两种解决方式:

1、 排除 web 内置容器

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- Maven整个生命周期内排除内置容器,排除内置容器导出成war包可以让外部容器运行spring-boot项目-->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

2、使用 spring-webflux 模块

webflux 有一个全新的非堵塞的函数式 Reactive Web 框架,可以用来构建异步的、非堵塞的、事件驱动的服务

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

成功启动项目

gateway与spring-boot-starter-web冲突问题的解决

gateway 网关版本冲突问题

1、spring-cloud版本

<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>

2、sprring-boot版本

<version>2.0.3.RELEASE</version>

3、错误描述

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-05-21 16:53:50.138 ERROR 15308 --- [ 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.

4、原因

<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>

版本冲突

5、解决

可以删除:

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

以上为个人经验,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Java/Android 相关文章推荐
浅析NIO系列之TCP
Jun 15 Java/Android
启动Tomcat时出现大量乱码的解决方法
Jun 21 Java/Android
springboot拦截器无法注入redisTemplate的解决方法
Jun 27 Java/Android
Java基础之详解HashSet的使用方法
Jun 30 Java/Android
SpringBoot SpringEL表达式的使用
Jul 25 Java/Android
dubbo服务整合zipkin详解
Jul 26 Java/Android
Spring Security中用JWT退出登录时遇到的坑
Oct 16 Java/Android
springboot如何接收application/x-www-form-urlencoded类型的请求
Nov 02 Java/Android
Java实现学生管理系统(IO版)
Feb 24 Java/Android
SpringBoot2零基础到精通之数据库专项精讲
Mar 22 Java/Android
Android开发实现极为简单的QQ登录页面
Apr 24 Java/Android
springboot创建的web项目整合Quartz框架的项目实践
Jun 21 Java/Android
springboot集成springCloud中gateway时启动报错的解决
Jul 16 #Java/Android
JavaWeb 入门篇(3)ServletContext 详解 具体应用
JavaWeb 入门:Hello Servlet
JavaWeb 入门篇:创建Web项目,Idea配置tomcat
mybatis 获取无数据的字段不显示的问题
Jul 15 #Java/Android
Lombok的详细使用及优缺点总结
Jul 15 #Java/Android
Java Socket实现多人聊天系统
You might like
thinkPHP的Html模板标签使用方法
2012/11/13 PHP
如何用php获取文件名后缀
2013/06/09 PHP
PHP递归复制、移动目录的自定义函数分享
2014/11/18 PHP
WordPress的主题编写中获取头部模板和底部模板
2015/12/28 PHP
php支付宝系列之电脑网站支付
2018/05/30 PHP
juqery 学习之三 选择器 子元素与表单
2010/11/25 Javascript
javascript 构造函数强制调用经验总结
2012/12/02 Javascript
8个实用的jQuery技巧
2014/03/04 Javascript
jquery实现适用于门户站的导航下拉菜单效果代码
2015/08/24 Javascript
jQuery定义插件的方法
2015/12/18 Javascript
jQuery实现简单隔行变色的方法
2016/02/20 Javascript
14 个折磨人的 JavaScript 面试题
2016/08/08 Javascript
JavaScript使用简单正则表达式的数据验证功能示例
2017/01/13 Javascript
javascript帧动画(实例讲解)
2017/09/02 Javascript
浅谈VUE监听窗口变化事件的问题
2018/02/24 Javascript
axios简单实现小程序延时loading指示
2018/07/30 Javascript
webpack优化之代码分割与公共代码提取详解
2019/11/22 Javascript
React实现轮播效果
2020/08/25 Javascript
[52:57]2014 DOTA2国际邀请赛中国区预选赛 LGD-CDEC VS HGT
2014/05/21 DOTA
Linux环境下MySQL-python安装过程分享
2015/02/02 Python
对于Python装饰器使用的一些建议
2015/06/03 Python
Python中序列的修改、散列与切片详解
2017/08/27 Python
python+opencv实现高斯平滑滤波
2020/07/21 Python
Centos部署django服务nginx+uwsgi的方法
2019/01/02 Python
python matplotlib 画dataframe的时间序列图实例
2019/11/20 Python
python 变量初始化空列表的例子
2019/11/28 Python
pandas中read_csv的缺失值处理方式
2019/12/19 Python
Python3实现监控新型冠状病毒肺炎疫情的示例代码
2020/02/13 Python
python使用turtle库绘制奥运五环
2020/02/24 Python
python爬取代理IP并进行有效的IP测试实现
2020/10/09 Python
CSS3 中的@keyframes介绍
2014/09/02 HTML / CSS
老教师工作总结的自我评价
2013/09/27 职场文书
合伙经营协议书范本(通用版)
2014/12/03 职场文书
稽核岗位职责
2015/02/10 职场文书
vue3.0 数字翻牌组件的使用方法详解
2022/04/20 Vue.js
ubuntu下常用apt命令介绍
2022/06/05 Servers