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 相关文章推荐
Spring Boot两种全局配置和两种注解的操作方法
Jun 29 Java/Android
java固定大小队列的几种实现方式详解
Jul 15 Java/Android
Java SSM配置文件案例详解
Aug 30 Java/Android
logback 实现给变量指定默认值
Aug 30 Java/Android
Java spring定时任务详解
Oct 05 Java/Android
Java 在生活中的 10 大应用
Nov 02 Java/Android
解决springboot druid数据库连接失败后一直重连的方法
Apr 19 Java/Android
Java线程的6种状态与生命周期
May 11 Java/Android
Java实现字符串转为驼峰格式的方法详解
Jul 07 Java/Android
SpringBoot接入钉钉自定义机器人预警通知
Jul 15 Java/Android
Java Spring读取和存储详细操作
Aug 05 Java/Android
Java中的Kafka为什么性能这么快及4大核心详析
Sep 23 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
自动跳转中英文页面
2006/10/09 PHP
ThinkPHP3.1新特性之对页面压缩输出的支持
2014/06/19 PHP
php大小写转换函数(strtolower、strtoupper)用法介绍
2017/11/17 PHP
菜鸟javascript基础资料整理2
2010/12/06 Javascript
jQuery模拟超链接点击效果代码
2013/04/21 Javascript
Javascript中的String对象详谈
2014/03/03 Javascript
jQuery Validation PlugIn的使用方法详解
2015/12/18 Javascript
Node.js的npm包管理器基础使用教程
2016/05/26 Javascript
大型JavaScript应用程序架构设计模式
2016/06/29 Javascript
javascript类型系统——日期Date对象全面了解
2016/07/13 Javascript
AngularJS实现给动态生成的元素绑定事件的方法
2016/12/14 Javascript
js如何判断是否在iframe中及防止网页被别站用iframe嵌套
2017/01/11 Javascript
微信小程序删除处理详解
2017/08/16 Javascript
详解Angular4 路由设置相关
2017/08/26 Javascript
vue-cli 自定义指令directive 添加验证滑块示例
2017/10/19 Javascript
AngularJS实现的2048小游戏功能【附源码下载】
2018/01/03 Javascript
Vue在 Nuxt.js 中重定向 404 页面的方法
2019/04/23 Javascript
VUE 单页面使用 echart 窗口变化时的用法
2020/07/30 Javascript
python实现文件分组复制到不同目录的例子
2014/06/04 Python
Python实例分享:快速查找出被挂马的文件
2014/06/08 Python
Python编程中的文件操作攻略
2015/10/16 Python
python脚本设置超时机制系统时间的方法
2016/02/21 Python
解决PyCharm中光标变粗的问题
2017/08/05 Python
Python图像处理之图像的读取、显示与保存操作【测试可用】
2019/01/04 Python
Appium+Python自动化测试之运行App程序示例
2019/01/23 Python
Python 中PyQt5 点击主窗口弹出另一个窗口的实现方法
2019/07/04 Python
PyQt5基本控件使用之消息弹出、用户输入、文件对话框的使用方法
2019/08/06 Python
Python virtualenv虚拟环境实现过程解析
2020/04/18 Python
Windows下pycharm安装第三方库失败(通用解决方案)
2020/09/17 Python
如何利用python正则表达式匹配版本信息
2020/12/09 Python
《春天来了》教学反思
2014/04/07 职场文书
居委会个人对照检查材料思想汇报
2014/09/29 职场文书
幼儿园教师管理制度
2015/08/05 职场文书
2016年八一建军节活动总结
2016/04/05 职场文书
导游词之江西赣州
2019/10/15 职场文书
Python通过m3u8文件下载合并ts视频的操作
2021/04/16 Python