如何在 spring 云中使用 eureka.client.service-url: 属性 of netflix eureka

How to use eureka.client.service-url: property of netflix eureka in spring cloud

我正在尝试在其中一个微服务中添加 Eureka 客户端,但我无法弄清楚我是否可以使用该服务-url.

我正在使用 spring-cloud 的 Greenwich.SR1 版本。

下面是我的application.yml

spring:
  application:
    name: stock-service

server:
  port: 9901

eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url: http://${eureka.instance.hostname}:9902/eureka/

我试图搜索出来,但到处都是这个版本不支持的旧方法:

旧方法:

eureka:         #tells about the Eureka server details and its refresh time
  instance:
    leaseRenewalIntervalInSeconds: 1
    leaseExpirationDurationInSeconds: 2
  client:
    serviceUrl:
      defaultZone: http://127.0.0.1:8761/eureka/ 

有人可以帮忙吗?

终于找到配置了:

spring:
  application:
    name: stock-service

server:
  port: 9901

eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      default-zone: http://localhost:9902/eureka

我刚刚在 Spring Cloud Hoxton.SR4 中尝试了这个配置,但它不起作用。 然后我找到了正确的方法(至少对我来说):

spring:
  application:
    name: hello-world-server

server:
  port: 8010

eureka:
  client:
    service-url:
      defaultZone: http://localhost:9001/eureka/

我们可以在启动您的客户端应用程序后看到以下日志:

2020-05-02 16:39:21.914  INFO 27104 --- [           main] c.n.d.DiscoveryClient                    : Discovery Client initialized at timestamp 1588408761914 with initial instances count: 0
2020-05-02 16:39:21.915  INFO 27104 --- [           main] o.s.c.n.e.s.EurekaServiceRegistry        : Registering application HELLO-WORLD-SERVER with eureka with status UP
2020-05-02 16:39:21.915  INFO 27104 --- [           main] c.n.d.DiscoveryClient                    : Saw local status change event StatusChangeEvent [timestamp=1588408761915, current=UP, previous=STARTING]
2020-05-02 16:39:21.916  INFO 27104 --- [nfoReplicator-0] c.n.d.DiscoveryClient                    : DiscoveryClient_HELLO-WORLD-SERVER/tumbleweed:hello-world-server:8010: registering service...

服务器端:

有效!