当前位置:网站首页>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包即可
边栏推荐
- Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
- 数据分析之缺失值填充(重点讲解多重插值法Miceforest)
- MySQL占用内存过大解决方案
- Générateur d'identification distribué basé sur redis
- FreeRTOS 任务函数里面的死循环
- [esp32 learning-1] construction of Arduino esp32 development environment
- Fashion-Gen: The Generative Fashion Dataset and Challenge 论文解读&数据集介绍
- JS object and event learning notes
- JS變量類型以及常用類型轉換
- 共用体(union)详解【C语言】
猜你喜欢

Detailed explanation of 5g working principle (explanation & illustration)

Fashion-Gen: The Generative Fashion Dataset and Challenge 论文解读&数据集介绍

Arduino JSON data information parsing

基於Redis的分布式ID生成器

History object

Common properties of location

Cannot change version of project facet Dynamic Web Module to 2.3.

RT-Thread 线程的时间片轮询调度

Kaggle competition two Sigma connect: rental listing inquiries (xgboost)

Comparaison des solutions pour la plate - forme mobile Qualcomm & MTK & Kirin USB 3.0
随机推荐
基于Redis的分布式锁 以及 超详细的改进思路
基於Redis的分布式ID生成器
Fashion-Gen: The Generative Fashion Dataset and Challenge 论文解读&数据集介绍
小天才电话手表 Z3工作原理
OPPO VOOC快充电路和协议
RT-Thread的main线程“卡死”的一种可能原因及解决方案
FreeRTOS 任务函数里面的死循环
imgcat使用心得
Comparison of solutions of Qualcomm & MTK & Kirin mobile platform USB3.0
js 变量作用域和函数的学习笔记
The dolphin scheduler remotely executes shell scripts through the expect command
List and set
1081 rational sum (20 points) points add up to total points
Common properties of location
Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
Types de variables JS et transformations de type communes
arduino UNO R3的寄存器写法(1)-----引脚电平状态变化
列表的使用
2022.2.12 resumption
Machine learning -- decision tree (sklearn)