Spring boot 找不到网关的服务调用
我从春云开始 我创建了3个应用程序,一个用于发现服务,一个用于网关,一个用于服务。 我实际上没有使用spring云配置和任何负载平衡 对于我的发现Spring boot 找不到网关的服务调用,spring-boot,spring-cloud,Spring Boot,Spring Cloud,我从春云开始 我创建了3个应用程序,一个用于发现服务,一个用于网关,一个用于服务。 我实际上没有使用spring云配置和任何负载平衡 对于我的发现 server.port=8761 spring.application.name=discovery-service eureka.instance.hostname=localhost eureka.client.registerWithEureka=false eureka.client.fetchRegistry=false eureka.
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=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/
我知道旅舍服务是在探索服务中注册的
注册实例hotel-SERVICE/192.168.102.129:hotel-SERVICE:9000
状态为UP(复制=false)
我去看电影时一定要看清楚
当我试着打电话时
或
我得到一个404错误
如果我这样做
我得到了很好的结果
编辑
github上的代码
hotels应用程序在服务发现中注册,但网关应用程序没有注册。将
'org.springframework.cloud:spring cloud starter netflix eureka client'
添加到build.gradle
中的实现
依赖项-然后它将在eureka和http://localhost:8080/hostels
请求将被路由到招待所
应用程序。网关需要eureka.client.serviceUrl.defaultZone=http://localhost:8061/eureka/
对eureka(端口8061)的调用永远不会用eureka.client.serviceUrl.defaultZone键代理任何相同的错误,但代理只能在端口8080上工作。你是说这样不行?(因为你改变了你的问题)8080上的结果是相同的,但我认为这将适用于此url:但需要使用它来确定使用path
谓词进入路由的内容,然后在lb:///之后使用提供的服务id通过负载平衡器传递匹配的内容。您没有以/hostel service/hostels
开头的路径谓词定义路由。