Spring Cloud:API网关路由不工作



我正在使用Spring Cloud。我的春季启动应用程序college-servicestudent-serviceeureka-serverapi-gateway中有四个服务。我正在尝试使用API网关调用college-servicestudent-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路径匹配。

可能的解决方案:

  1. StudentController请求映射从/college更改为/student
  2. 为学生服务使用不同的谓词,例如Host
  3. 设置特定的路径谓词并更改路由的顺序:
routes:
- id: student-service
uri: lb://student-service
predicates:
- Path=/college/student/**
- id: college-service
uri: lb://college-service
predicates:
- Path=/college/**

最新更新