欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

gateway與spring-boot-starter-web沖突問題的解決

 更新時(shí)間:2021年07月16日 17:16:45   作者:Chen DingFeng  
這篇文章主要介紹了gateway與spring-boot-starter-web沖突問題的解決,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

gateway與spring-boot-starter-web 沖突

環(huán)境:

SpringCloud 版本 ---- Finchley.SR2

SpringBoot 版本 ---- 2.0.6.RELEASE

問題描述:

將 zuul 網(wǎng)關(guān)升級(jí)為 gateway 時(shí),引入gateway 依賴啟動(dòng)網(wǎng)關(guān)子項(xiàng)目報(bào)錯(cuò)

引入的依賴:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>

啟動(dòng)網(wǎng)關(guān)報(bào)錯(cuò)

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

問題分析:

查看控制臺(tái)打印日志:

可以看到是 web 依賴下的 tomcat 容器啟動(dòng)失敗,且打印出 nio 異常。

回顧一下 zuul 和 gateway 的區(qū)別

Zuul: 構(gòu)建于 Servlet 2.5,兼容3.x,使用的是阻塞式的API,不支持長連接,比如 websockets。

Gateway構(gòu)建于 Spring 5+,基于 Spring Boot 2.x 響應(yīng)式的、非阻塞式的 API。同時(shí),它支持 websockets,和 Spring 框架緊密集成

報(bào)錯(cuò)原因:啟動(dòng)時(shí)默認(rèn)使用了 spring-boot-starter-web 的內(nèi)置容器,不支持非阻塞

問題解決:

有兩種解決方式:

1、 排除 web 內(nèi)置容器

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- Maven整個(gè)生命周期內(nèi)排除內(nèi)置容器,排除內(nèi)置容器導(dǎo)出成war包可以讓外部容器運(yùn)行spring-boot項(xiàng)目-->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

2、使用 spring-webflux 模塊

webflux 有一個(gè)全新的非堵塞的函數(shù)式 Reactive Web 框架,可以用來構(gòu)建異步的、非堵塞的、事件驅(qū)動(dòng)的服務(wù)

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

成功啟動(dòng)項(xiàng)目

gateway 網(wǎng)關(guān)版本沖突問題

1、spring-cloud版本

<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>

2、sprring-boot版本

<version>2.0.3.RELEASE</version>

3、錯(cuò)誤描述

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>

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • quartz定時(shí)執(zhí)行任務(wù),并配置web.xml的操作方法

    quartz定時(shí)執(zhí)行任務(wù),并配置web.xml的操作方法

    下面小編就為大家?guī)硪黄猶uartz定時(shí)執(zhí)行任務(wù),并配置web.xml的操作方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-07-07
  • Redis?command?timed?out兩種異常情況的解決方式

    Redis?command?timed?out兩種異常情況的解決方式

    Redis是我們開發(fā)中常用的數(shù)據(jù)庫,下面這篇文章主要給大家介紹了關(guān)于Redis?command?timed?out兩種異常情況的解決方式,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-04-04
  • 基于tomcat8 編寫字符編碼Filter過濾器無效問題的解決方法

    基于tomcat8 編寫字符編碼Filter過濾器無效問題的解決方法

    下面小編就為大家分享一篇基于tomcat8 編寫字符編碼Filter過濾器無效問題的解決方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • java實(shí)現(xiàn)工資管理簡單程序

    java實(shí)現(xiàn)工資管理簡單程序

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)工資管理簡單程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • 深入了解JAVA數(shù)據(jù)類型與運(yùn)算符

    深入了解JAVA數(shù)據(jù)類型與運(yùn)算符

    這篇文章主要介紹了Java基本數(shù)據(jù)類型和運(yùn)算符,結(jié)合實(shí)例形式詳細(xì)分析了java基本數(shù)據(jù)類型、數(shù)據(jù)類型轉(zhuǎn)換、算術(shù)運(yùn)算符、邏輯運(yùn)算符等相關(guān)原理與操作技巧,需要的朋友可以參考下
    2021-07-07
  • C++字符串的處理詳解

    C++字符串的處理詳解

    這篇文章主要介紹了C++ string字符串類,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-08-08
  • Hutool開發(fā)利器MapProxy類使用技巧詳解

    Hutool開發(fā)利器MapProxy類使用技巧詳解

    這篇文章主要為大家介紹了Hutool開發(fā)利器MapProxy類使用技巧詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • Java中的單例模式詳解(完整篇)

    Java中的單例模式詳解(完整篇)

    Java單例模式應(yīng)該是看起來以及用起來簡單的一種設(shè)計(jì)模式,但是就實(shí)現(xiàn)方式以及原理來說,也并不淺顯,下面這篇文章主要給大家介紹了關(guān)于Java中單例模式的相關(guān)資料,需要的朋友可以參考下
    2021-11-11
  • Java ThreadPoolExecutor的參數(shù)深入理解

    Java ThreadPoolExecutor的參數(shù)深入理解

    這篇文章主要介紹了Java ThreadPoolExecutor的參數(shù)深入理解的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • java數(shù)組元素的引用實(shí)例講解

    java數(shù)組元素的引用實(shí)例講解

    在本篇文章里小編給大家整理的是一篇關(guān)于java數(shù)組元素的引用實(shí)例講解內(nèi)容,有需要的朋友們可以學(xué)習(xí)參考下。
    2021-03-03

最新評論