找不到网关对服务的调用
Call to service by the gateway is not found
我从 spring 云开始。
我创建了 3 个应用程序,一个用于发现服务,一个用于网关,一个是服务。
我实际上没有使用 spring 云配置和任何负载平衡
为了我的发现
server.port=8761
spring.application.name=discovery-service
eureka.instance.hostname=localhost
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
对于我的网关
#Port for Registry service
server.port=8080
spring.application.name=gateway-service
spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.routes[0].id=hostel-service
spring.cloud.gateway.routes[0].uri=lb://hostel-service
spring.cloud.gateway.routes[0].predicates[0]=Path=/hostels/**
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
我的旅馆服务
server.port=9000
spring.application.name=hostel-service
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
我看到旅馆服务已在发现服务中注册
Registered instance HOSTEL-SERVICE/192.168.102.129:hostel-service:9000
with status UP (replication=false)
我去的时候看看http://localhost:8761/
当我尝试调用
http://localhost:8080/hostels
or
http://localhost:8080/hostel-service/hostels
我收到 404 错误
如果我这样做
我取得了不错的成绩
编辑
github
上的代码
https://github.com/mctdi/hostel
https://github.com/mctdi/gateway
https://github.com/mctdi/discovery
hostels
应用程序在服务发现中注册,但 gateway
应用程序未注册。在 build.gradle
中添加 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
给你 implementation
依赖 - 然后它将在 Eureka 中注册并且 http://localhost:8080/hostels
请求将被路由到 hostels
应用程序。
我从 spring 云开始。
我创建了 3 个应用程序,一个用于发现服务,一个用于网关,一个是服务。 我实际上没有使用 spring 云配置和任何负载平衡
为了我的发现
server.port=8761
spring.application.name=discovery-service
eureka.instance.hostname=localhost
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
对于我的网关
#Port for Registry service
server.port=8080
spring.application.name=gateway-service
spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.routes[0].id=hostel-service
spring.cloud.gateway.routes[0].uri=lb://hostel-service
spring.cloud.gateway.routes[0].predicates[0]=Path=/hostels/**
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
我的旅馆服务
server.port=9000
spring.application.name=hostel-service
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
我看到旅馆服务已在发现服务中注册
Registered instance HOSTEL-SERVICE/192.168.102.129:hostel-service:9000 with status UP (replication=false)
我去的时候看看http://localhost:8761/
当我尝试调用
http://localhost:8080/hostels or http://localhost:8080/hostel-service/hostels
我收到 404 错误
如果我这样做
我取得了不错的成绩
编辑
github
上的代码https://github.com/mctdi/hostel
https://github.com/mctdi/gateway
https://github.com/mctdi/discovery
hostels
应用程序在服务发现中注册,但 gateway
应用程序未注册。在 build.gradle
中添加 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
给你 implementation
依赖 - 然后它将在 Eureka 中注册并且 http://localhost:8080/hostels
请求将被路由到 hostels
应用程序。