Spring Cloud整合配置中心Eureka中的服务状态显示UNKOWN

今天在研究Spring Cloud的配置中心的时候,发现将应用的配置移到git上,启动应用后发现,在Euraka注册中心上这个应用的状态始终为UNKOWN,可是这个应用是可以提供服务的。下面是应用的bootstrap的配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
spring:
application:
name: search-provider
cloud:
config:
name: search-config
profile: dev
label: master
discovery:
enabled: true
service-id: config-server
eureka:
client:
fetch-registry: true
register-with-eureka: true
healthcheck:
enabled: true
service-url:
defaultZone: http://xxxx:xxxx@xxx.ydstudio.net:xxx/eureka/
instance:
#instance-id默认值是主机名:应用名:应用端口 instance-id: ${spring.application.name}:${random.value}
#instance-id: ${spring.cloud.client.ipAddress}:${server.port}
instance-id: ${spring.cloud.client.ipAddress}:${spring.application.name}:${server.port}
hostname: ${spring.cloud.client.ipAddress}
#hostname: ${spring.application.name}
# 默认30s,表示eureka client发送心跳给server端的频率
lease-renewal-interval-in-seconds: 15
# 默认90s,表示eureka server至上一次收到client的心跳之后,等待下一次心跳的超时时间,在这个时间内若没收到下一次心跳,则将移除该instance
lease-expiration-duration-in-seconds: 25
# 将自己的ip显示到EuekaServer上
prefer-ip-address: true

日志打印应用的状态:

1
StatusChangeEvent [timestamp=1536481926709, current=UNKNOWN, previous=UP]

这些配置肯定没有什么问题,因为这些配置在没有挪到bootstrap.yml中之前都是可以正常使用的。现在Eureka注册中心却不能检测到应用的状态,这样让我百思不得其解。后来我在stackoverflow上找到了答案
stackoverflow地址,问题只有一个答案,其中重要内容如下:

1
eureka.client.healthcheck.enabled=true should only be set in  application.yml. Setting the value in bootstrap.yml will cause undesirable side effects like registering in eureka with an  UNKNOWN status.

知道这一点后我将bootstrap.yml中的内容修改如下面一样:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

spring:
application:
name: search-provider
cloud:
config:
name: search-config
profile: dev
label: master
#uri: http://localhost:9008
discovery:
enabled: true
service-id: config-server

eureka:
client:
service-url:
defaultZone: http://xxxx:xxxx@xxx.ydstudio.net:xxx/eureka/

在Eureka注册中心中应用的状态就显示正常了!

  • 作者: Sam
  • 发布时间: 2018-09-09 23:42:27
  • 最后更新: 2019-12-09 23:03:26
  • 文章链接: https://ydstudios.gitee.io/post/5e4a0e78.html
  • 版权声明: 本网所有文章除特别声明外, 禁止未经授权转载,违者依法追究相关法律责任!