我正在使用Spring Cloud。我的春季启动应用程序college-service
、student-service
、eureka-server
和api-gateway
中有四个服务。我正在尝试使用API网关调用college-service
和student-service
。当我从API网关调用我的college-service
时,工作正常,但student-service
不工作。当我尝试获取student-serivice
时,发现错误404
未找到。我是春云的新人。下面是我的密码。
下面是我的url,在最后一个url中我得到了404
URL | 状态 |
---|---|
http://localhost:9001/college/CLG01 | 200正常 |
http://localhost:9002/college/student/CLG01 | 200正常 |
http://localhost:9003/college/CLG01 | 200正常 |
http://localhost:9003/college/student/CLG01 | 400未找到 |
student-service
的谓词是匹配以student(Path=/student/**
(开头的所有请求。然而,你打电话给student-service
,请求从大学开始(/college/student/CLG01
(。此请求将与college-service
匹配,因为您将此服务的谓词设置为Path=/college/**
。CCD_ 17路径与CCD_ 18路径匹配。
可能的解决方案:
- 将
StudentController
请求映射从/college
更改为/student
- 为学生服务使用不同的谓词,例如
Host
- 设置特定的路径谓词并更改路由的顺序:
routes:
- id: student-service
uri: lb://student-service
predicates:
- Path=/college/student/**
- id: college-service
uri: lb://college-service
predicates:
- Path=/college/**