概述
config包括服务器和客户端,还需要git和一个远程http仓库
客户端读取配置,服务器从http远程仓库读取配置,此文件用于项目来使用,十几个配置文件可以交给远程仓库来管理
更新配置,可以使用git向远程http仓库上传配置文件
使用
1.注册gitee账号,建立远程仓库.
将远程仓库下拉到本地 使用 git clone https/ssh地址
上传配置文件到远程仓库
git add 文件名/全部(.)
git commit -m ‘提交备注’
git push origin master
2.新建工程cloud config
pom.xml加入核心依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
3.application.xml https方式连接,填码云的用户名和密码
4.新建启动类
package com.yan.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
/**
* @Author: 闫明辉
* @Description:
* @Date: Create in 15:48 2020/3/11
*/
@SpringBootApplication
@EnableConfigServer
public class Config_3344_StartSpringCloudApp {
public static void main(String[] args) {
SpringApplication.run(Config_3344_StartSpringCloudApp.class,args);
}
}
5.windows下hosts文件加入映射
127.0.0.1 config-3344.com
搭建完成!
6.测试能否访问配置文件内容
官网访问形式
application即SpringApplication中spring.config.name(即常规的Spring Boot应用程序中通常是“应用程序”)
profile 指的是配置文件名字
laber 是可选的,它代表git的分支标签。默认为master
访问:config-3344.com:3344/application-dev.yml
参考资料:尚硅谷周阳Spring Cloud讲解