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
SpringBoot2 参数管理实践之入参出参与校验的方式
Jun 16 Java/Android
分析设计模式之模板方法Java实现
Jun 23 Java/Android
Java 数组内置函数toArray详解
Jun 28 Java/Android
RestTemplate如何通过HTTP Basic Auth认证示例说明
Mar 17 Java/Android
Java 超详细讲解hashCode方法
Apr 07 Java/Android
Java设计模式之代理模式
Apr 22 Java/Android
java版 联机五子棋游戏
May 04 Java/Android
Spring IOC容器Bean的作用域及生命周期实例
May 30 Java/Android
Android学习之BottomSheetDialog组件的使用
Jun 21 Java/Android
详解Spring Security如何在权限中使用通配符
Jun 28 Java/Android
Java Redisson多策略注解限流
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
PHP 模拟$_PUT实现代码
2010/03/15 PHP
PHP中如何实现常用邮箱的基本判断
2014/01/07 PHP
php中函数前加&amp;符号的作用分解
2014/07/08 PHP
PHP实现二叉树的深度优先与广度优先遍历方法
2015/09/28 PHP
php将数组存储为文本文件方法汇总
2015/10/28 PHP
Yii2框架RESTful API 格式化响应,授权认证和速率限制三部分详解
2016/11/10 PHP
PHP仿qq空间或朋友圈发布动态、评论动态、回复评论、删除动态或评论的功能(上)
2017/05/26 PHP
PHP删除数组中指定下标的元素方法
2018/02/03 PHP
jquery实现漂浮在网页右侧的qq在线客服插件示例
2013/05/13 Javascript
js中Math之random,round,ceil,floor的用法总结
2013/12/26 Javascript
JavaScript中的apply和call函数详解
2014/07/20 Javascript
JS中使用sort结合localeCompare实现中文排序实例
2014/07/23 Javascript
JavaScript中的对象的extensible属性介绍
2014/12/30 Javascript
javascript与Python快速排序实例对比
2015/08/10 Javascript
jquery中val()方法是从最后一个选项往前读取的
2015/09/06 Javascript
微信小程序开发实战教程之手势解锁
2016/11/18 Javascript
JavaScript的兼容性与调试技巧
2016/11/22 Javascript
bootstrap3中container与container_fluid外层容器的区别讲解
2017/12/04 Javascript
vue中nextTick用法实例
2019/09/11 Javascript
jQuery实现鼠标放置名字上显示详细内容气泡提示框效果的方法分析
2020/04/04 jQuery
如何在postman测试用例中实现断言过程解析
2020/07/09 Javascript
python 网络编程详解及简单实例
2017/04/25 Python
CentOS 7下Python 2.7升级至Python3.6.1的实战教程
2017/07/06 Python
python实现图书借阅系统
2019/02/20 Python
python查看文件大小和文件夹内容的方法
2019/07/08 Python
pandas read_excel()和to_excel()函数解析
2019/09/19 Python
python GUI库图形界面开发之PyQt5选项卡控件QTabWidget详细使用方法与实例
2020/03/01 Python
HTML5 实战PHP之Web页面表单设计
2011/10/09 HTML / CSS
什么时候用assert
2015/05/08 面试题
大学生村官心得体会范文
2014/01/04 职场文书
二手房买卖协议书
2014/04/10 职场文书
电子商务优秀毕业生求职信
2014/07/11 职场文书
读《皮囊》有感:理解是对他人的最大的善举
2019/11/14 职场文书
html+css实现滚动到元素位置显示加载动画效果
2021/08/02 HTML / CSS
Vue2.0搭建脚手架
2022/03/13 Vue.js
分享几个简单MySQL优化小妙招
2022/03/31 MySQL