Spring Cloud Config笔记总结

创建一个git仓库:

1、 搭建一个git服务或者使用github私有仓库

2、 在git服务中创建一个仓库用于存放我们的配置文件

3、 比如创建名为:siki-xhb-config

4、 在仓库中创建目录:siki-xhb-repository

5、 在目录下创建与服务名相同的文件名:siki-xhb-hello-dev.yml

6、 在各个服务名相同的文件夹下创建我们不同环境的配置文件

一、Config Server

1、 引入Spring Cloud Config依赖

	 <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>

2、 在启动类上加上注解,来加载config Server
@EnableConfigServer
3、 在配置文件中配置我们的Config Server配置

spring:
  application:
    name: siki-xhb-config
  cloud:
    config:
      server:
        git:
          uri: https://github.com/ccl125/siki-xhb-config.git			  			//配置文件存放地址
          search-paths: siki-xhb-repository/{
    
    application},{
    
    application}				//仓库的文件目录
          username: ccl125															//git用户
          password: xxxxxx													 		//git密码	
          skipSslValidation: true													//忽略ssl验证
          default-label: main														//指定main分枝

二、Config Client

1、 引入config client依赖

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

2、 将配置文件名改为bootstrap.yml

3、 添加config client 配置

spring:
  application:
    name: siki-xhb-hello
  profiles:
    active: dev									//配置环境(开发)
  cloud:
    config:
      uri: http://192.168.101.23:40003			//注册中心的Config Server地址
      name: ${
    
    spring.application.name}			//配置文件名称
      profile: ${
    
    spring.profiles.active}		//后缀

猜你喜欢

转载自blog.csdn.net/qq_44900959/article/details/113646344