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 相关文章推荐
JPA如何使用entityManager执行SQL并指定返回类型
Jun 15 Java/Android
详解Java分布式事务的 6 种解决方案
Jun 26 Java/Android
mybatis 解决从列名到属性名的自动映射失败问题
Jun 30 Java/Android
springboot+zookeeper实现分布式锁
Mar 21 Java/Android
Java字符串逆序方法详情
Mar 21 Java/Android
零基础学java之方法的定义与调用详解
Apr 10 Java/Android
JAVA长虹键法之建造者Builder模式实现
Apr 10 Java/Android
Jmerte 分布式压测及分布式压测配置
Apr 30 Java/Android
Java 数组的使用
May 11 Java/Android
Java实现带图形界面的聊天程序
Jun 10 Java/Android
java.util.NoSuchElementException原因及两种解决方法
Jun 28 Java/Android
Java获取字符串编码格式实现思路
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程序的方法
2009/03/09 PHP
PHP 将图片按创建时间进行分类存储的实现代码
2010/01/05 PHP
PHP5常用函数列表(分享)
2013/06/07 PHP
Dwz与thinkphp整合下的数据导出到Excel实例
2014/12/04 PHP
PHP中使用imagick生成PSD文件缩略图教程
2015/01/26 PHP
用Javascript同时提交多个Web表单的方法
2009/12/26 Javascript
jQuery中append、insertBefore、after与insertAfter的简单用法与注意事项
2020/04/04 Javascript
js日历功能对象
2012/01/12 Javascript
JavaScript按位运算符的应用简析
2014/02/04 Javascript
JavaScript中this关键词的使用技巧、工作原理以及注意事项
2014/05/20 Javascript
通过Jquery的Ajax方法读取将table转换为Json
2014/05/31 Javascript
node.js中的fs.rmdir方法使用说明
2014/12/16 Javascript
jQuery搜索框效果实现代码(百度关键词联想)
2021/02/25 Javascript
js canvas实现放大镜查看图片功能
2017/06/08 Javascript
浅谈 Vue v-model指令的实现原理
2017/06/08 Javascript
原生js获取left值和top值的三种方法
2017/08/02 Javascript
JS操作时间 - UNIX时间戳的简单介绍(必看篇)
2017/08/16 Javascript
element ui分页多选,翻页记忆的实例
2019/09/03 Javascript
用smtplib和email封装python发送邮件模块类分享
2014/02/17 Python
python实现在字符串中查找子字符串的方法
2015/07/11 Python
Python实现带参数与不带参数的多重继承示例
2018/01/30 Python
python 爬虫 批量获取代理ip的实例代码
2018/05/22 Python
Python使用numpy模块实现矩阵和列表的连接操作方法
2019/06/26 Python
python3.7 使用pymssql往sqlserver插入数据的方法
2019/07/08 Python
python提取照片坐标信息的实例代码
2019/08/14 Python
Python Handler处理器和自定义Opener原理详解
2020/03/05 Python
TensorFlow实现模型断点训练,checkpoint模型载入方式
2020/05/26 Python
python time.strptime格式化实例详解
2021/02/03 Python
css3实现3D文本悬停改变效果的示例代码
2019/01/16 HTML / CSS
巴西家用小家电购物网站:Polishop
2016/08/07 全球购物
临时工聘用合同协议书
2014/10/29 职场文书
2015年精神文明建设工作总结
2015/04/21 职场文书
在校证明模板
2015/06/17 职场文书
学生会部长竞选稿
2015/11/19 职场文书
nginx proxy_cache 缓存配置详解
2021/03/31 Servers
OpenCV实现普通阈值
2021/11/17 Java/Android