首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用eureka.client.service-url: spring云中netflix eureka的属性

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

Stack Overflow用户
提问于 2019-06-09 19:10:52
回答 2查看 6.7K关注 0票数 4

我正尝试在其中一个微服务中添加Eureka客户端,但我无法确定是否可以使用service-url。

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

下面是我的application.yml

代码语言:javascript
复制
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/

我试着搜索它,但到处都是这个版本不支持的老方法:

老方法:

代码语言:javascript
复制
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/ 

有人能帮帮忙吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-06-10 13:59:23

最后,我找到了配置:

代码语言:javascript
复制
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
票数 6
EN

Stack Overflow用户

发布于 2020-05-02 16:50:12

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

代码语言:javascript
复制
spring:
  application:
    name: hello-world-server

server:
  port: 8010

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

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

代码语言:javascript
复制
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...

和服务器端:

它起作用了!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56514100

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档