我正在尝试使用尤里卡发现服务器、API 网关和一项休息服务的微服务。如下图所示
对于服务发现:
application.yml:-
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
对于 Spring boot 服务 1:-
application.yml
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
对于 Api 网关服务:-
application.yml
server:
port: 9009
spring:
application:
name: HEALTH-CARD
eureka:
instance:
hostname: localhost
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://${eureka.instance.hostname}:8761/eureka/
server:
port: 9009
spring:
application:
name: HEALTH-CARD
eureka:
instance:
hostname: localhost
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://${eureka.instance.hostname}:8761/eureka/
即使我已经尝试了下面链接中的所有建议 Spring Cloud API 网关路由不起作用 但对我来说没有任何作用。请帮我处理这个有线外壳。 [1]:
您可能想尝试在应用程序 yaml 中减少 Spring Cloud 行
server:
port: 8080
spring:
application:
name: API-GATEWAY
cloud:
gateway:
discovery:
locator:
enabled: true
routes:
- id: health-card
uri: http://localhost:9009/health-card
predicates:
- Path=/**
eureka:
instance:
hostname: localhost
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://${eureka.instance.hostname}:8761/eureka/
server:
port: 8080
spring:
application:
name: API-GATEWAY
cloud:
gateway:
discovery:
locator:
enabled: true
routes:
- id: health-card
uri: http://localhost:9009/health-card
predicates:
- Path=/**
eureka:
instance:
hostname: localhost
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://${eureka.instance.hostname}:8761/eureka/
是
package com.apigateway.config;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SpringApiGatewayConfig {
public RouteLocator configRoute(RouteLocatorBuilder builder) {
return builder.routes()
.route("healthCard", r->r.path("/health-card/**").uri("localhost:9009/")).build();
}
}
的同级,您的示例在小时候就有它。