问题描述: 在使用springcloud搭建项目时,使用gateway网关,nacos服务上都配置正常,在application.properties中的配置也没有问题,使用原先端口访问的时候正常,但使用gateway端口访问时浏览器报错内容Service Unavailable 503错误,具体如下:

Error Page This application has no configured error view, so you are seeing this as a fallback.
Fri Oct 17 11:52:25 CST 2025 [bf617cff-2] There was an unexpected error (type=Service Unavailable, status=503)

解决方法:
这里我springcloud的版本是2021.0.1的,而springcloud alibaba在2020版之后不支持ribbon,但gateway使用的就是ribbon,所以我们需要使用loadbalancer替代ribbon,首先在gateway模块的pom.xml的配置中添加

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

同时在application.properties文件中禁用ribbon

# 禁用ribbon
spring.cloud.loadbalancer.ribbon.enabled=false

重启服务,gateway就生效了

更多推荐