Spring Cloud Config
服务端:一个集中化配置中心,可以是一个独立的服务,也可以注册到服务治理中心,它可以集中管理各个 微服务的配置; 作用原理是从某个地方读取(本地/云端)提供给其客户端作为配置;
客户端:作为一个服务端,通过读取Config的服务端来获取自己的配置文件;
服务端核心代码:
1,服务端配置
spring:
  cloud:
    config:
      server:
        git: 
# 配置文件的git地址,如果需要密码,则需要配置用户名密码
          uri: https://gitee.com/varyu-program/config-repo
#          username: 18596103896
#          password: 95594597@Gavin 
#          配置仓库的版本
#          default-label: master 
#          配置文件的文件地址
#          search-paths: /
  application:
    name: config-center
server:
  port: 4001 
 
启动类上:
@EnableConfigServer
@SpringBootApplication(scanBasePackages = "com.gavin.*")
public class ConfigserverApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigserverApplication.class, args);
    }
} 
 
 
 
 
 
2,客户端配置:
spring:
  application:
#    //这里的配置文件名要跟git仓库中的一致(没有前缀)
    name: config-client
  cloud:
    config:
      uri: http://localhost:4001
#      快速失败避免长期读取不到服务端配置而长期占用资源
      fail-fast: false
#      label: master
  profiles:
#    这里指定了配置文件的后缀部分, spring.application.name spring.profiles.active 组成git仓库中的文件名,spring.cloud.config.label确定读取的分支
    active: v1 
 
注意客户端配置文件名 为bootstrap.yml

高版本的spring组件会禁用 bootstrap.yml的加载,此时需要引入该组件即可:
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
    <version>3.0.3</version>
</dependency> 
 
 
启动服务端,在启动客户端:
客户端启动时部分日志:











![buuctf_练[羊城杯2020]easyphp](https://img-blog.csdnimg.cn/img_convert/4e502050faa2b63867786d283ff7735a.png)








