springcloud 2020 gateway 503 錯誤代碼

POM文件依賴

<dependencies>

? ? <dependency>

? ? ? ? <groupId>org.springframework.boot</groupId>

? ? ? ? <artifactId>spring-boot-starter</artifactId>

? ? </dependency>

? ? <!--gateway fhadmin.org-->

? ? <dependency>

? ? ? ? <groupId>org.springframework.cloud</groupId>

? ? ? ? <artifactId>spring-cloud-starter-gateway</artifactId>

? ? ? ? <version>3.0.2</version>

? ? </dependency>

? ? <!--spring-boot fhadmin.org-->

? ? <dependency>

? ? ? ? <groupId>org.springframework.boot</groupId>

? ? ? ? <artifactId>spring-boot-starter-test</artifactId>

? ? ? ? <scope>test</scope>

? ? </dependency>

</dependencies>

我在父組件中加入的nacos的相關(guān)依賴如下:

<dependency>

? ? <groupId>com.alibaba.cloud</groupId>

? ? <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>

? ? <version>${nacos.version}</version>

</dependency>

<!--alibaba fhadmin.org-->

<dependency>

? ? <groupId>com.alibaba.cloud</groupId>

? ? <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>

? ? <version>${nacos.version}</version>

</dependency>

nacos的版本如下:

<properties>

? ? <nacos.version>2021.1</nacos.version>

</properties>

gateway的application.yml文件配置如下:

#fhadmin.org

server:

? port: 9040

spring:

? application:

? ? name: gateway

? cloud:

? ? gateway:

? ? ? routes:

? ? ? ? - id: consumer

? ? ? ? ? uri: lb://consumer

? ? ? ? ? #? ? ? ? ? uri: http://localhost:9010

? ? ? ? ? predicates:

? ? ? ? ? ? - Path=/**

? ? nacos:

? ? ? discovery:

? ? ? ? server-addr: localhost:8848

? ? ? ? metadata:

? ? ? ? ? preserved.heart.beat.interval: 3 #心跳間隔。時間單位:秒。心跳間隔

? ? ? ? ? preserved.heart.beat.timeout: 6 #心跳暫停。時間單位:秒。 即服務(wù)端6秒收不到客戶端心跳,會將該客戶端注冊的實例設(shè)為不健康:

? ? ? ? ? preserved.ip.delete.timeout: 9 #Ip刪除超時。時間單位:秒。即服務(wù)端9秒收不到客戶端心跳,會將該客戶端注冊的實例刪除:

當我通過uri: http://localhost:9010去調(diào)用服務(wù)時,是可以調(diào)用的,但是當我用uri lb://consumer時就無法調(diào)用服務(wù),報錯503.

解決辦法是:

加入feign依賴。

<dependencies>

? ? <dependency>

? ? ? ? <groupId>org.springframework.boot</groupId>

? ? ? ? <artifactId>spring-boot-starter</artifactId>

? ? </dependency>

? ? <dependency>

? ? ? ? <groupId>org.springframework.cloud</groupId>

? ? ? ? <artifactId>spring-cloud-starter-gateway</artifactId>

? ? ? ? <version>3.0.2</version>

? ? </dependency>

? ? <!--fegin組件 fhadmin.org-->

? ? <dependency>

? ? ? ? <groupId>org.springframework.cloud</groupId>

? ? ? ? <artifactId>spring-cloud-starter-openfeign</artifactId>

? ? ? ? <version>3.0.2</version>

? ? </dependency>

? ? <!-- Feign Client for loadBalancing -->

? ? <dependency>

? ? ? ? <groupId>org.springframework.cloud</groupId>

? ? ? ? <artifactId>spring-cloud-loadbalancer</artifactId>

? ? ? ? <version>3.0.2</version>

? ? </dependency>

? ? <dependency>

? ? ? ? <groupId>org.springframework.boot</groupId>

? ? ? ? <artifactId>spring-boot-starter-test</artifactId>

? ? ? ? <scope>test</scope>

? ? </dependency>

</dependencies>

猜測原因:nacos兼容feign,feign集成ribbon,默認實現(xiàn)負載均衡;或許是nacos不兼容springcloud gateway自帶的ribbon。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容