springcloud config客户端 无法读取git的配置文件

springcloud 服务端能够连接git 并正常访问,但是config客户端不能连接到git的配置文件,利用bootstrap优先级最高配置yml文件文件内容如下

spring:
  cloud:
    config:
      name: microservicecloud-config-client #需要从github上读取的资源名称,注意没有yml后缀名
      profile: test   #本次访问的配置项
      label: master   
      uri: http://config-3344.com:3344  #本微服务启动后先去找3344号服务,通过SpringCloudConfig获取GitHub的服务地址

然后目录结构
image
接下来是ConfigClientRest类的代码实现

@RestController
public class ConfigClientRest {

    @Value("${spring.application.name}")
    private String applicationName;

    @Value("${eureka.client.service-url.defaultZone}")
    private String eurekaServers;

    @Value("${server.port}")
    private String port;

    @RequestMapping("/config")
    public String getConfig() {
        String str = "applicationName: " + applicationName + "\t eurekaServers:" + eurekaServers + "\t port: " + port;
        System.out.println("******str: " + str);
        return "applicationName: " + applicationName + "\t eurekaServers:" + eurekaServers + "\t port: " + port;
    }
}

git仓库的文件


启动对应的config客户端直接报错
异常信息如下
Could not resolve placeholder ‘eureka.client.service-url.defaultZone’ in value “${eureka.client.service-url.defaultZone}”

原因是我的git的文件有问题,我自己从新在idea重新写了一遍然后再次提交,解决了,初步估计,应该是编码和空格等问题。。。

1 个赞

楼主这么早就学了,今天也做到这里。这个bug找搞半天!!