首先我们将uri配置成本地地址测试服务是否可以调通
spring:cloud:nacos:discovery:server-addr: xxx.xxx.xxx.xxx:8848gateway:routes:- id: angular_appuri: http://localhost:8082predicates:- Path=/angular/**filters:- StripPrefix=1
xxx.xxx.xxx.xxx:8848 切换成你的nacos服务器地址
yanghaoyuan@yanghaoyuandeMacBook-Pro ~ % curl http://localhost:8080/angular/users
[{"id":1,"name":"张三","age":23,"email":"zhangsan@good.com","isDeleted":0,"createdDate":"2024-05-06T03:43:13","lastModifiedDate":null,"createdBy":"1","lastModifiedBy":null}]%
8080端口是本地gateway的服务端口,上面表明已经可以调通。
spring:cloud:nacos:discovery:server-addr: xxx.xxx.xxx.xxx:8848gateway:routes:- id: angular_appuri: lb://user-servicepredicates:- Path=/angular/**filters:- StripPrefix=1
换成 lb负载均衡的方式调用调不通,初步判断应该是没有添加lb的依赖包,所以lb的方式无法获取服务列表从而无法转发。
java"> <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-loadbalancer</artifactId><version>4.0.3</version></dependency>
在pom中添加lb的依赖,重启服务测试
yanghaoyuan@yanghaoyuandeMacBook-Pro ~ % curl http://localhost:8080/angular/users
[{"id":1,"name":"张三","age":23,"email":"zhangsan@good.com","isDeleted":0,"createdDate":"2024-05-06T03:43:13","lastModifiedDate":null,"createdBy":"1","lastModifiedBy":null}]%