1、用自己的账号在GitHub新建一个springcloud-config的新Repository

2、由上一步获得新建的git地址

3、在本地硬盘目录上新建git仓库并clone

4、此时在本地盘符下的文件

5、新建Module模块cloud-config-center-3344,它即为cloud的配置中心模块cloudConfig Center

6、POM

  1. <dependencies>
  2. <!--添加消息总线RabbitMQ支持-->
  3. <dependency>
  4. <groupId>org.springframework.cloud</groupId>
  5. <artifactId>spring-cloud-starter-bus-amqp</artifactId>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.springframework.cloud</groupId>
  9. <artifactId>spring-cloud-config-server</artifactId>
  10. </dependency>
  11. <dependency>
  12. <groupId>org.springframework.cloud</groupId>
  13. <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  14. </dependency>
  15. <dependency>
  16. <groupId>org.springframework.boot</groupId>
  17. <artifactId>spring-boot-starter-web</artifactId>
  18. </dependency>
  19. <dependency>
  20. <groupId>org.springframework.boot</groupId>
  21. <artifactId>spring-boot-starter-actuator</artifactId>
  22. </dependency>
  23. <dependency>
  24. <groupId>org.springframework.boot</groupId>
  25. <artifactId>spring-boot-devtools</artifactId>
  26. <scope>runtime</scope>
  27. <optional>true</optional>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.projectlombok</groupId>
  31. <artifactId>lombok</artifactId>
  32. <optional>true</optional>
  33. </dependency>
  34. <dependency>
  35. <groupId>org.springframework.boot</groupId>
  36. <artifactId>spring-boot-starter-test</artifactId>
  37. <scope>test</scope>
  38. </dependency>
  39. </dependencies>

7、YML

8、主启动

9、测试通过Config微服务是否可以从GitHub是否可以从GitHub上获取配置内容

1、启动服务3344

2、http://localhost:3344/master/config-dev.yml

image.png

10、读取配置规则

第一种:
/{label}/{application}-{profile}.yml
/{application}-{profile}.yml
/{application}-{profile}.yml
/{application}/{profile}/{/label}
第二种:
/{application}-{profile}.yml
第三种:
/{application}/{profile}[/{lable}]

lable:分支(branch)
name:服务名
profiles:环境(dev/test/prod)