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 26 Java/Android
Java常用工具类汇总 附示例代码
Jun 26 Java/Android
Java 中的 Unsafe 魔法类的作用大全
Jun 26 Java/Android
探讨Java中的深浅拷贝问题
Jun 26 Java/Android
SpringBoot读取Resource下文件的4种方法
Jul 02 Java/Android
新手初学Java网络编程
Jul 07 Java/Android
Spring实现内置监听器
Jul 09 Java/Android
Log4j.properties配置及其使用
Aug 02 Java/Android
Java完整实现记事本代码
Jun 16 Java/Android
Spring Boot 的创建和运行示例代码详解
Jul 23 Java/Android
HttpClient实现表单提交上传文件
Aug 14 Java/Android
Android移动应用开发指南之六种布局详解
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学习 变量使用总结
2011/03/24 PHP
关于PHP的相似度计算函数:levenshtein的使用介绍
2013/04/15 PHP
ThinkPHP写数组插入与获取最新插入数据ID实例
2014/11/03 PHP
PHP实现简单实用的验证码类
2015/07/29 PHP
PHP实现linux命令tail -f
2016/02/22 PHP
静态图片的十一种滤镜效果--不支持Ie7及非IE浏览器。
2007/03/06 Javascript
javascript面向对象包装类Class封装类库剖析
2013/01/24 Javascript
用js写了一个类似php的print_r输出换行功能
2013/02/18 Javascript
jQuery中end()方法用法实例
2015/01/08 Javascript
JS实现仿腾讯微博无刷新删除微博效果代码
2015/10/16 Javascript
jQuery文字轮播特效
2017/02/12 Javascript
nodejs搭建本地服务器轻松解决跨域问题
2018/03/21 NodeJs
浅析JS中什么是自定义react数据验证组件
2018/10/19 Javascript
vue 源码解析之虚拟Dom-render
2019/08/26 Javascript
jquery 插件重新绑定的处理方法分析
2019/11/23 jQuery
js实现拖动缓动效果
2020/01/13 Javascript
微信小程序间使用navigator跳转传值问题实例分析
2020/03/27 Javascript
python在命令行下使用google翻译(带语音)
2014/01/16 Python
Python与shell的3种交互方式介绍
2015/04/11 Python
Python函数的周期性执行实现方法
2016/08/13 Python
python+opencv实现摄像头调用的方法
2019/06/22 Python
Python中低维数组填充高维数组的实现
2019/12/02 Python
Python API 操作Hadoop hdfs详解
2020/06/06 Python
英国街头品牌:Bee Inspired Clothing
2018/02/12 全球购物
美国正宗设计师眼镜在线零售商:EYEZZ
2019/03/23 全球购物
Under Armour安德玛荷兰官网:美国高端运动科技品牌
2019/07/10 全球购物
自荐书封面下载
2013/11/29 职场文书
动员大会主持词
2014/03/20 职场文书
社区先进事迹材料
2014/05/19 职场文书
人力资源部岗位职责
2015/02/11 职场文书
军训个人总结
2015/03/03 职场文书
学校食堂食品安全承诺书
2015/04/29 职场文书
股东出资协议书
2016/03/21 职场文书
六年级作文之关于梦
2019/10/22 职场文书
python执行js代码的方法
2021/05/13 Python
Redis实战之Lettuce的使用技巧详解
2022/12/24 Redis