Springboot报错:Fail fast is set and there was an error reading configuration from consul

Springboot报错:Fail fast is set and there was an error reading configuration from consul

今天搭建springboot集成consul配置中心的时候遇到如下报错

2021-02-09 11:50:11.787 [main] ERROR o.s.c.c.c.ConsulPropertySourceLocator:154 - Fail fast is set and there was an error reading configuration from consul.

点进源码断点查看,看到以下报错导致:
在这里插入图片描述
复制出来是这个

com.ecwid.consul.transport.TransportException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8500 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect

然后断点到里面看到:
在这里插入图片描述
这里显示的consul地址是:localhost:8500
然后我们实际配置的是:

spring:
  application:
    name: game-gateway-server
  cloud:
    consul:
      host: 127.0.0.1
      port: 2000
      scheme:
      discovery:
        service-name: ${spring.application.name}
        prefer-ip-address: true #表示注册时使用ip而不是hostname
        instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port} #实例id
        register: true #配置服务注册
        deregister: true #服务停止时取消注册
        health-check-critical-timeout: 30s  #健康检查失败多长时间取消注册
      config:
        enabled: true # 启用配置中心
        prefix: test
        format: KEY_VALUE # 表示consul上面文件的格式 有四种 YAML PROPERTIES KEY-VALUE FILES
        data-key: data #表示consul上面的KEY值(或者说文件的名字) 默认是data

说明consul拉取配置中心的时候,我们的配置并未生效

解决办法:

创建bootstrap.yml,将配置拷贝到bootstrap.yml里面去

spring:
  application:
    name: game-gateway-server
  cloud:
    consul:
      host: 127.0.0.1
      port: 2000
      scheme:
      discovery:
        service-name: ${spring.application.name}
        prefer-ip-address: true #表示注册时使用ip而不是hostname
        instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port} #实例id
        register: true #配置服务注册
        deregister: true #服务停止时取消注册
        health-check-critical-timeout: 30s  #健康检查失败多长时间取消注册
      config:
        enabled: true # 启用配置中心
        prefix: test
        format: KEY_VALUE # 表示consul上面文件的格式 有四种 YAML PROPERTIES KEY-VALUE FILES
        data-key: data #表示consul上面的KEY值(或者说文件的名字) 默认是data

再次重启,读取成功

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值