目录
创建远程仓库
- 在 gitee 中,右上角点加号新建仓库
- 设置仓库名
- 设置成开源项目
创建本地仓库
- vcs -- create git repository
- 选择项目工程文件夹作为本地仓库目录
- 向本地仓库提交文件
- 选中全部文件、填写提交信息,执行提交
业务模块的配置文件,放到 git 仓库
1. 在项目工程中新建文件夹:config
2. 复制业务模块的 application.yml 到 config 目录
- item-service-dev.yml
- user-service-dev.yml
- order-service-dev.yml
3. 三个文件中添加 `override-none: true`
防止下载的配置,覆盖本地参数设置
spring:
cloud:
config:
override-none: true
4. 提交到本地仓库
5. 向远程仓库推送
搭建配置中心
1. 新建 config 模块
2. 添加 config server 、eureka client 依赖
<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>
3. yml配置
```yml
git 仓库地址
仓库中存放配置文件的文件夹路径
```
spring:
application:
name: config-server
cloud:
config:
server:
git:
#后面出现错误的话,可能是远程仓库有问题
#或者仓库中文件夹路径不对
#或者是仓库中的配置文件不对
uri: Git仓库地址
search-paths: config
server:
port: 6001
eureka:
client:
service-url:
defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka
4. 启动类注解:`@EnalbeConfigServer`
修改业务模块的 application.yml,代码全部注释
添加config client依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
新建 bootstrap.yml (在引导配置阶段,从配置中心下载 application.yml)
- 添加三条配置:
- 连接 eureka
- 指定配置中心的服务id
- 从配置中心下载 user-service-dev.yml
eureka:
client:
service-url:
defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka
spring:
cloud:
config:
discovery:
enabled: true
service-id: config-server
name: item-service
profile: dev