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 相关文章推荐
教你用Java在个人电脑上实现微信扫码支付
Jun 13 Java/Android
Java框架入门之简单介绍SpringBoot框架
Jun 18 Java/Android
Java并发编程之Executor接口的使用
Jun 21 Java/Android
浅谈自定义校验注解ConstraintValidator
Jun 30 Java/Android
Java使用httpRequest+Jsoup爬取红蓝球号码
Jul 02 Java/Android
SpringBoot快速入门详解
Jul 21 Java/Android
浅谈spring boot使用thymeleaf版本的问题
Aug 04 Java/Android
正则表达式拆分url实例代码
Feb 24 Java/Android
Java 超详细讲解hashCode方法
Apr 07 Java/Android
Java Spring Boot请求方式与请求映射过程分析
Jun 25 Java/Android
基于Android10渲染Surface的创建过程
Aug 14 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
在PHP3中实现SESSION的功能(一)
2006/10/09 PHP
在PHP中读取和写入WORD文档的代码
2008/04/09 PHP
THINKPHP截取中文字符串函数实例代码
2017/03/20 PHP
JQuery UI皮肤定制
2009/07/27 Javascript
jQuery toggle()设置CSS样式
2009/11/05 Javascript
javascript实现数字+字母验证码的简单实例
2014/02/10 Javascript
jquery中val()方法是从最后一个选项往前读取的
2015/09/06 Javascript
用AngularJS的指令实现tabs切换效果
2016/08/31 Javascript
js实现String.Fomat的实例代码
2016/09/02 Javascript
node.js学习之base64编码解码
2016/10/21 Javascript
Vue.js 2.0中select级联下拉框实例
2017/03/06 Javascript
详解webpack 配合babel 将es6转成es5 超简单实例
2017/05/02 Javascript
JavaScript 值类型和引用类型的初次研究(推荐)
2017/07/19 Javascript
angular写一个列表的选择全选交互组件的示例
2018/01/22 Javascript
element ui 对话框el-dialog关闭事件详解
2018/02/26 Javascript
vue 实现剪裁图片并上传服务器功能
2018/03/01 Javascript
Vue单页应用引用单独的样式文件的两种方式
2018/03/30 Javascript
Rollup处理并打包JS文件项目实例代码
2018/05/31 Javascript
vuex实现购物车的增加减少移除
2020/06/28 Javascript
状态机的概念和在Python下使用状态机的教程
2015/04/11 Python
Python删除空文件和空文件夹的方法
2015/07/14 Python
在cmd中运行.py文件: python的操作步骤
2018/05/12 Python
Python socket套接字实现C/S模式远程命令执行功能案例
2018/07/06 Python
可能是最全面的 Python 字符串拼接总结【收藏】
2018/07/09 Python
python 实现将txt文件多行合并为一行并将中间的空格去掉方法
2018/12/20 Python
Windows下Pycharm远程连接虚拟机中Centos下的Python环境(图文教程详解)
2020/03/19 Python
Python+redis通过限流保护高并发系统
2020/04/15 Python
使用scrapy ImagesPipeline爬取图片资源的示例代码
2020/09/28 Python
Python排序函数的使用方法详解
2020/12/11 Python
CSS3教程(1):什么是CSS3
2009/04/02 HTML / CSS
岗位标兵事迹材料
2014/05/17 职场文书
人事任命书怎么写
2014/06/05 职场文书
党的群众路线剖析材料
2014/10/09 职场文书
防汛通知
2015/04/25 职场文书
银行大堂经理培训心得体会
2016/01/09 职场文书
大学迎新生的欢迎词
2019/06/25 职场文书