1

我第一次使用spring cloud gateway。我的服务端点是http://localhost:8080/student/getlist

问题是,当我尝试使用云网关调用我的服务时,它给了我 404。尤里卡正确显示了服务 URL

我的网关属性如下

spring.application.name=gateway
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
server.port=8085
management.endpoints.web.exposure.include=*

spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.routes.id=student-service
spring.cloud.gateway.routes.uri=lb://student-service
spring.cloud.gateway.routes.predicates.Path=/student/**

下面是网关中的执行器路由

[{"route_id":"CompositeDiscoveryClient_GATEWAY","route_definition":{"id":"CompositeDiscoveryClient_GATEWAY","predicates":[{"name":"Path","args":{"pattern":"/GATEWAY/**"}}],"filters":[{"name":"RewritePath","args":{"regexp":"/GATEWAY/(?<remaining>.*)","replacement":"/${remaining}"}}],"uri":"lb://GATEWAY","order":0},"order":0},{"route_id":"CompositeDiscoveryClient_STUDENT-SERVICE","route_definition":{"id":"CompositeDiscoveryClient_STUDENT-SERVICE","predicates":[{"name":"Path","args":{"pattern":"/STUDENT-SERVICE/**"}}],"filters":[{"name":"RewritePath","args":{"regexp":"/STUDENT-SERVICE/(?<remaining>.*)","replacement":"/${remaining}"}}],"uri":"lb://STUDENT-SERVICE","order":0},"order":0}]

我试图通过网关调用服务端点

http://localhost:8085/student/getlist

上面的 URL 但这不起作用。我究竟做错了什么。任何微服务都没有上下文路径。示例代码在

https://github.com/ojith97/sample.git
4

2 回答 2

0

你必须让网关知道尤里卡服务器

eureka.client.service-url.defaultZone=http://user:pass@localhost:8761/eureka

然后使阻止网关注册到尤里卡

eureka.client.register-with-eureka=false

第二个选项很重要,因为它会导致使用 lb:servicename 结构进行负载平衡时出现 404 错误。

于 2020-11-28T17:20:06.583 回答
0

尝试将您的属性更改为

spring.cloud.gateway.routes[0].id=student-service
spring.cloud.gateway.routes[0].uri=lb://student-service
spring.cloud.gateway.routes[0].predicates[0]=Path=/student/**
于 2019-09-20T09:21:34.457 回答