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输出Hello World完美过程解析
Jun 13 Java/Android
Java内存模型之happens-before概念详解
Jun 13 Java/Android
Java实现简易的分词器功能
Jun 15 Java/Android
Java面试题冲刺第十九天--数据库(4)
Aug 07 Java/Android
详解JAVA的控制语句
Nov 11 Java/Android
Java tomcat手动配置servlet详解
Nov 27 Java/Android
springboot新建项目pom.xml文件第一行报错的解决
Jan 18 Java/Android
Spring Security使用单点登录的权限功能
Apr 03 Java/Android
教你在 Java 中实现 Dijkstra 最短路算法的方法
Apr 08 Java/Android
Springboot-cli 开发脚手架,权限认证,附demo演示
Apr 28 Java/Android
Android存储中最基本的文件存储方式
Apr 30 Java/Android
openGauss数据库JDBC环境连接配置的详细过程(Eclipse)
Jun 01 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
JavaScript中的onerror事件概述及使用
2013/04/01 Javascript
jquery1.10给新增元素绑定事件的方法
2014/03/06 Javascript
jQuery获取动态生成的元素示例
2014/06/15 Javascript
JS实现网页顶部向下滑出的全国城市切换导航效果
2015/08/22 Javascript
完全深入学习Bootstrap表单
2016/11/28 Javascript
Vue.js 2.0学习教程之从基础到组件详解
2017/04/24 Javascript
vue的Virtual Dom实现snabbdom解密
2017/05/03 Javascript
详解Angular2 关于*ngFor 嵌套循环
2017/05/22 Javascript
激动人心的 Angular HttpClient的源码解析
2017/07/10 Javascript
使用JavaScript实现一个小程序之99乘法表
2017/09/21 Javascript
vue-resource请求实现http登录拦截或者路由拦截的方法
2018/07/11 Javascript
浅谈React碰到v-if
2018/11/04 Javascript
Python 调用Java实例详解
2017/06/02 Python
Python实现删除列表中满足一定条件的元素示例
2017/06/12 Python
TensorFlow安装及jupyter notebook配置方法
2017/09/08 Python
selenium+python自动化测试之使用webdriver操作浏览器的方法
2019/01/23 Python
Django中信号signals的简单使用方法
2019/07/04 Python
用Python从0开始实现一个中文拼音输入法的思路详解
2019/07/20 Python
Python中print函数简单使用总结
2019/08/05 Python
Python使用指定字符长度切分数据示例
2019/12/05 Python
pytorch 实现cross entropy损失函数计算方式
2020/01/02 Python
通过实例解析python描述符原理作用
2020/01/22 Python
python利用google翻译方法实例(翻译字幕文件)
2020/09/21 Python
Python全局变量与global关键字常见错误解决方案
2020/10/05 Python
基于css3的属性transition制作菜单导航效果
2015/09/01 HTML / CSS
html5 datalist标签使用示例(自动完成组件)
2014/05/04 HTML / CSS
全天然狗零食:Best Bully Sticks
2016/09/22 全球购物
说出数据连接池的工作机制是什么?
2013/04/19 面试题
事业单位接收函
2014/01/10 职场文书
竞聘上岗演讲稿范文
2014/01/10 职场文书
人事经理岗位职责
2014/04/28 职场文书
大型公益活动策划方案
2014/08/20 职场文书
装修活动策划方案
2014/08/27 职场文书
乡镇组织委员个人整改措施
2014/09/16 职场文书
读《庄子》有感:美而不自知
2019/11/06 职场文书
postgresql中如何执行sql文件
2023/05/08 PostgreSQL