Spring Cloud Config Client不能访问Config Server的问题解决

今天在配置Spring Cloud Config Client读取Config Server在gitee的配置文件时,出现了使用URI方式不能正常读取Config Server配置的问题。

Spring cloud版本:Greenwich.SR2

Spring Boot版本:2.1.6.RELEASE

Spring Cloud和Spring Boot版本比较多,但是它们之间有明确的对应关系,可以去查询具体的对应版本(传送门:https://spring.io/projects/spring-cloud#overview

此问题,具体的Config Server核心配置(bootstrap.yml)如下:

  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/username/springcloud-config-server
          username:
          password:
          search-paths: config-files
          default-label: master

此配置,经过测试没有发现问题,Config Server可以正常同步在gitee上的配置文件。

ConfigServer同步信息
ConfigServer从Git同步的文件,如上图所示,已同步成功

Config Client的核心配置部分(bootstrap.yml)如下:

spring:
  cloud:
    config:
      name: config-client
      label: master
      profile: dev
      uri: http://localhost:7002

上面文件采用URI的同步访问方式,启动后控制台没有打印出fetching config from server http://localhost:7002等的提示信息,很明显是Config Client访问Config Server出现的问题,中间尝试过很多网上搜索的方法,包括bootstrap从yml换成properties;更换配置文件从yml到properties等等均没有解决。尝试换一种配置方式,通过查找eureka注册中心的Config Server的Application name,配置如下:

spring:
  application:
    name: config-client
  cloud:
    config:
      discovery:
        enabled: true
        service-id: config-server #config server的注册application name
      profile: dev
      label: master

如下图,久违的fetching信息出现,问题解决。至于为什么使用URI不能访问,暂时还没有找到原因。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值