spring cloud gateway与nacos整合报503错误
最近做spring cloud中的gateway组件与nacos的整合测试,application.yml的配置如下:
server:
port: 8222 #服务端口
spring:
application:
name: service-gateway #服务名
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848 #nacos服务地址
gateway:
discovery:
locator:
enabled: true #使用服务发现路由
routes:
- id: service-edu #路由的id
uri: lb://service-edu #服务名
predicates:
- Path=/eduservice/** #路由的匹配路径
浏览器访问http://localhost:8222/eduservice/teacher/findAll,结果报503错误,nacos里面也有相应的服务,后来到网上查了发现是因为少了一个依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
添加了依赖以后,重启服务,测试成功
完整的依赖如下
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
原文链接:https://blog.csdn.net/woshihedayu/article/details/116148882