我正尝试在其中一个微服务中添加Eureka客户端,但我无法确定是否可以使用service-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/ 有人能帮帮忙吗?
发布于 2019-06-10 13:59:23
最后,我找到了配置:
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发布于 2020-05-02 16:50:12
我刚刚在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...和服务器端:

它起作用了!
https://stackoverflow.com/questions/56514100
复制相似问题