我是第一次使用spring云网关。我的服务端点是http://localhost:8080/student/getlist
问题是,当我试图使用云网关调用我的服务时,它给了我404。eureka正确显示了服务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}]im正在尝试通过网关调用服务端点
http://localhost:8085/student/getlist上面的URL,但这不起作用。我做错了什么。没有指向任何微服务的上下文路径。示例代码在
https://github.com/ojith97/sample.git发布于 2019-09-20 17:21:34
尝试将您的属性更改为
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/**发布于 2020-11-29 01:20:07
您必须用下面的代码让网关知道eureka服务器
eureka.client.service-url.defaultZone=http://user:pass@localhost:8761/eureka
然后使阻止网关注册到eureka
eureka.client.register-with-eureka=false
第二个选项很重要,因为它会导致使用lb:servicename结构的负载均衡出现404个错误。
https://stackoverflow.com/questions/52492834
复制相似问题