当前位置:网站首页>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包即可
边栏推荐
- R & D thinking 01 ----- classic of embedded intelligent product development process
- [template] KMP string matching
- VIM command line notes
- Basic operations of databases and tables ----- view data tables
- Variable star user module
- Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
- 列表的使用
- Basic operations of databases and tables ----- modifying data tables
- RT-Thread的main线程“卡死”的一种可能原因及解决方案
- Arduino gets the length of the array
猜你喜欢

ES6 grammar summary -- Part I (basic)

Togglebutton realizes the effect of switching lights

高通&MTK&麒麟 手機平臺USB3.0方案對比

arduino UNO R3的寄存器写法(1)-----引脚电平状态变化

Common properties of location

ESP学习问题记录

History object

E-commerce data analysis -- salary prediction (linear regression)

Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries

JS regular expression basic knowledge learning
随机推荐
Raspberry pie tap switch button to use
Bubble sort [C language]
Page performance optimization of video scene
Arm pc=pc+8 is the most understandable explanation
gcc 编译选项
Kconfig Kbuild
高通&MTK&麒麟 手機平臺USB3.0方案對比
Dead loop in FreeRTOS task function
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree
Custom view puzzle getcolor r.color The color obtained by colorprimary is incorrect
JS数组常用方法的分类、理解和运用
Pytoch implements simple linear regression demo
小天才电话手表 Z3工作原理
Cannot change version of project facet Dynamic Web Module to 2.3.
Kaggle competition two Sigma connect: rental listing inquiries
STM32 如何定位导致发生 hard fault 的代码段
Priority inversion and deadlock
There are three iPhone se 2022 models in the Eurasian Economic Commission database
Mp3mini playback module Arduino < dfrobotdfplayermini H> function explanation
Esp8266 connects to bafayun (TCP maker cloud) through Arduino IED