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 相关文章推荐
详解SpringBoot异常处理流程及原理
Jun 21 Java/Android
浅谈Python魔法方法
Jun 28 Java/Android
Java tomcat手动配置servlet详解
Nov 27 Java/Android
关于maven依赖 ${xxx.version}报错问题
Jan 18 Java/Android
SpringBoot2零基础到精通之异常处理与web原生组件注入
Mar 22 Java/Android
SpringBoot中使用Redis作为全局锁示例过程
Mar 24 Java/Android
Netty分布式客户端接入流程初始化源码分析
Mar 25 Java/Android
Java 获取Word中所有的插入和删除修订的方法
Apr 06 Java/Android
Java 多态分析
Apr 26 Java/Android
Android开发手册自定义Switch开关按钮控件
Jun 10 Java/Android
Mybatis-plus配置分页插件返回统一结果集
Jun 21 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
利用curl抓取远程页面内容的示例代码
2013/07/23 PHP
php小技巧之过滤ascii控制字符
2014/05/14 PHP
php防止恶意刷新与刷票的方法
2014/11/21 PHP
超强多功能php绿色集成环境详解
2017/01/25 PHP
Laravel框架之解决前端显示图片问题
2019/10/24 PHP
预加载css或javascript的js代码
2010/04/23 Javascript
JavaSript中变量的作用域闭包的深入理解
2014/05/12 Javascript
JavaScript日期时间与时间戳的转换函数分享
2015/01/31 Javascript
JavaScript使用indexOf获得子字符串在字符串中位置的方法
2015/04/06 Javascript
js绘制购物车抛物线动画
2020/11/18 Javascript
基于AngularJS实现iOS8自带的计算器
2016/09/12 Javascript
js控制div层的叠加简单方法
2016/10/15 Javascript
浅析Angular19 自定义表单控件
2018/01/31 Javascript
解决iView中时间控件选择的时间总是少一天的问题
2018/03/15 Javascript
Vue中的v-for循环key属性注意事项小结
2018/08/12 Javascript
浅谈Vue3 Composition API如何替换Vue Mixins
2020/04/29 Javascript
JavaScript实现多层颜色选项卡嵌套
2020/09/21 Javascript
Python 实现 贪吃蛇大作战 代码分享
2016/09/07 Python
Python 实现数据库(SQL)更新脚本的生成方法
2017/07/09 Python
Python Selenium Cookie 绕过验证码实现登录示例代码
2018/04/10 Python
PyQT实现多窗口切换
2018/04/20 Python
Python将list中的string批量转化成int/float的方法
2018/06/26 Python
python与字符编码问题
2019/05/24 Python
python requests包的request()函数中的参数-params和data的区别介绍
2020/05/05 Python
HTML5之多线程(Web Worker)
2019/01/02 HTML / CSS
高品质和独特的产品世界:Creations and Collections
2018/01/07 全球购物
毕业生精彩的自我评价分享
2013/10/06 职场文书
销售工作岗位职责
2013/12/24 职场文书
单位单身证明样本
2014/10/11 职场文书
司法局群众路线教育实践活动整改措施思想汇报
2014/10/13 职场文书
2016年6月份红领巾广播稿
2015/12/21 职场文书
SQLServer2019 数据库的基本使用之图形化界面操作的实现
2021/04/08 SQL Server
opencv用VS2013调试时用Image Watch插件查看图片
2021/07/26 Python
Python Matplotlib绘制条形图的全过程
2021/10/24 Python
草系十大最强宝可梦,纸片人上榜,榜首大家最熟悉
2022/03/18 日漫
微信小程序纯CSS实现无限弹幕滚动效果
2022/09/23 HTML / CSS