当前位置:网站首页>Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
2022-07-06 09:17:00 【阿杆.】
记一次路由转发失败的经历
使用gateway+nacos,yaml配置如下,这里使用的是服务名称进行转发:
server:
port: 10010
spring:
application:
name: @[email protected]
cloud:
nacos:
server-addr: 127.0.0.1:8848 # nacos地址
gateway:
discovery:
locator:
enabled: true
routes:
- id: blogtest # 路由标识,必须唯一
uri: lb://blogtest # 路由的目标地址,lb为load balance,负载均衡
predicates: # 路由断言,判断请求是否符合规则
- Path=/test/** # 判断请求是否以/user开头
pom文件如下:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
然后就出现了服务无法访问的情况,一直报错
Whitelabel Error Page
This application has no configured error view, so you are seeing this as a fallback.
Wed May 18 15:38:29 CST 2022
[fd8c3a90-7] There was an unexpected error (type=Service Unavailable, status=503).
关键是控制台也没报错,很正常的那种,就很让我怀疑是自己的问题。
后面把路由地址改了一下,改成了使用http地址进行转发:
gateway:
routes:
- id: blogtest
uri: http://127.0.0.1:1236 # 这里改了
predicates:
- Path=/test/**
然后再到浏览器发送请求,成功了,可以正常访问。
想了一下觉得可能是Nacos版本和我项目的依赖版本不匹配的问题,还去把Nacos降级了一波,结果还是不行。
原因
后面看到一篇博客:https://blog.csdn.net/qq_41953714/article/details/116239716
在pom.xml文件中添加了一个依赖:
<!--客户端负载均衡loadbalancer-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
重新启动,果然可以了。
原因引用原作者的话
由于springcloud2020弃用了Ribbon,因此Alibaba在2021版本nacos中删除了Ribbon的jar包,因此无法通过lb路由到指定微服务,出现了503情况。
所以只需要引入springcloud loadbalancer包即可
边栏推荐
- Bubble sort [C language]
- Programmers can make mistakes. Basic pointers and arrays of C language
- 機器學習--線性回歸(sklearn)
- 锂电池基础知识
- Mysqldump error1066 error solution
- Whistle+switchyomega configure web proxy
- Arm pc=pc+8 is the most understandable explanation
- Basic use of pytest
- 【ESP32学习-2】esp32地址映射
- Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
猜你喜欢
E-commerce data analysis -- salary prediction (linear regression)
RT-Thread 线程的时间片轮询调度
Navigator object (determine browser type)
機器學習--線性回歸(sklearn)
Générateur d'identification distribué basé sur redis
Kaggle competition two Sigma connect: rental listing inquiries (xgboost)
JS object and event learning notes
[esp32 learning-1] construction of Arduino esp32 development environment
Time slice polling scheduling of RT thread threads
Detailed explanation of 5g working principle (explanation & illustration)
随机推荐
Use of lists
Arduino get random number
数据分析之缺失值填充(重点讲解多重插值法Miceforest)
Walk into WPF's drawing Bing Dwen Dwen
Kconfig Kbuild
JS變量類型以及常用類型轉換
Page performance optimization of video scene
Unit test - unittest framework
高通&MTK&麒麟 手機平臺USB3.0方案對比
GNN的第一个简单案例:Cora分类
Pytoch temperature prediction
Rough analysis of map file
JS数组常用方法的分类、理解和运用
Inline detailed explanation [C language]
R & D thinking 01 ----- classic of embedded intelligent product development process
Missing value filling in data analysis (focus on multiple interpolation method, miseforest)
Mysqldump error1066 error solution
Esp8266 connects to onenet cloud platform (mqtt) through Arduino IDE
ESP8266通过arduino IED连接巴法云(TCP创客云)
Dependency in dependencymanagement cannot be downloaded and red is reported