文章目录
架构图
搭建git repository项目
配置文件 config-dev.yml
其他文件只是env的值不一样,为了区分不同的环境识别
person:
name: gaoxinfu
sex: man
age: 18
env: dev
源码地址
https://gitee.com/gaoxinfu_admin/demo-spring-cloud-config-center/tree/master/config
阶段1-搭建简单的config-server服务
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.gaoxinfu.demo.spring.cloud</groupId>
<artifactId>demo-spring-cloud-config</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo-spring-cloud-config Maven Webapp</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- spring cloud config 服务端包 -->
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-config-server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>demo-spring-cloud-config</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
启动类中引入配置中心注解 @EnableConfigServer
application.yml
server:
port: 8080
bootstrap.yml
spring:
application:
name: demo-spring-cloud-config # 应用名称
cloud:
config:
server:
git:
uri: https://gitee.com/gaoxinfu_admin/demo-spring-cloud-config-center #配置文件所在仓库
username: gaoxinfu_admin #登录账号
password: gxf6639848021@ #登录密码
default-label: master #配置文件分支
search-paths: config #配置文件所在根目录