spring-cloud-config 客户端获取配置时读取不到指定的文件

spring-cloud 2.2.5 config

一、config-server
1. pom.xml
<dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.springframework.cloud</groupId>-->
<!--            <artifactId>spring-cloud-starter-bus-amqp</artifactId>-->
<!--        </dependency>-->

        <!--admin客户端 -->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
        </dependency>

    </dependencies>
2.配置
server:
 port: 8889

spring:
 cloud:
   config:
     server:
       git:
         uri: https://gitee.com/zhongbangchao/all-config.git
         search-paths: '{application}'
         username: *****
         password: *****

 application:
   name: spring-cloud-config
eureka:
 client:
   service-url:
     defaultZone: http://localhost:9991/eureka/
management:
 endpoints:
   web:
     exposure:
       include: '*'
 endpoint:
   health:
     show-details: ALWAYS
二、config-client
1. pom.xml
 <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-client</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <!--admin客户端 -->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
        </dependency>

    </dependencies>

2. 配置
spring:
  application:
    name: instance
  cloud:
    config:
      uri: http://localhost:8889
      name: git-base-config,${spring.application.name}
      label: master

启动客户端会去配置中心拿指定的配置文件

name 这里如果一个实例放在一个文件夹中,文件夹名称与文件名前缀不一致会导致读取不到
例如:

spring.clouf.config.name=instance
git地址中instance.yml 文件放在instance1 文件夹下, 这样会读取不到这个文件。
把instance1 文件夹改为 instance 解决问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

chortryfree

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值