详解SpringCloud Config配置中心
2019-03-28 11:00
357 查看
一、创建Config配置中心项目
1.添加依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency>
2.启动类,需要添加@EnableConfigServer
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.server.EnableConfigServer; /** * @author fusw */ @SpringBootApplication @EnableConfigServer public class ConfigCenterApplication { public static void main(String[] args) { SpringApplication.run(ConfigCenterApplication.class, args); } }
3.配置文件
eureka.instance.appname=base-iov-config security.user.name=test security.user.password=test # GitLab 的配置方式,必须有 .git 后缀 # 配置默认 git 仓库的地址 spring.cloud.config.server.git.uri=http://xxxx/config-repo.git # git 仓库地址下的相对地址,可以配置多个,用“,”分割 spring.cloud.config.server.git.search-paths=* #配置中心clone仓库配置文件后存放的地址 spring.cloud.config.server.git.basedir=/data/deploy/config-repo spring.cloud.config.server.git.force-pull=true # git 仓库的账号 spring.cloud.config.server.git.username=test # git 仓库的密码 spring.cloud.config.server.git.password=test # 配置 其它git 仓库的地址 spring.cloud.config.server.git.repos.x.uri, iot为例 spring.cloud.config.server.git.repos.iot.uri=http://xxxx/iot/config-repo.git spring.cloud.config.server.git.repos.iot.search-paths=* spring.cloud.config.server.git.repos.iot.basedir=/data/deploy/config-repo spring.cloud.config.server.git.repos.iot.force-pull=true # git 仓库的账号 spring.cloud.config.server.git.repos.iot.username=test # git 仓库的密码 spring.cloud.config.server.git.repos.iot.password=test #前缀一定要配置,用来和默认仓库区分 spring.cloud.config.server.git.repos.iot.pattern=Iot* #注册中心 eureka.client.serviceUrl.defaultZone=http://xxx/eureka/
二、git 存放配置的仓库
创建一个git仓库用来存放各项目配置,可以在项目一级目录根据项目创建文件夹(各项目文件夹的名称可以随便起,Config配置中心只根据配置文件名找配置),然后各个项目文件夹存放不同环境的配置文件,
例如:
Iot-TestProject-dev.yml
Iot-TestProject-prd.yml
Iot-TestProject-test.yml
最好不要放置test.yml类似的默认配置,如果在各个项目配置文件中没有用spring.profiles.active指明使用的配置文件,那么会加载默认的配置文件。
三、各个SpringCloud的项目配置接入配置中心
在resource下的bootstrap.properties配置文件中,配置中心的相关配置如下
# 使用默认仓库的配置文件 spring.cloud.config.name=TestProject # 使用iot厂库的配置文件 #spring.cloud.config.name=Iot-TestProject #使用哪个环境的配置文件,和上面的配置配合,决定了使用哪一个配置文件:TestProject -test.yml spring.cloud.config.profile=test # 对应 存放配置文件仓库的git分支 spring.cloud.config.label=master spring.cloud.config.username=test spring.cloud.config.password=test # 开启 Config 服务发现支持 spring.cloud.config.discovery.enabled=true # 指定 Server 端的 name,也就是 Server 端 spring.application.name 的值 spring.cloud.config.discovery.serviceId=base-iov-config
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
- 详解使用spring cloud config来统一管理配置文件
- Spring Cloud Config Client超时及重试示例详解
- Spring Cloud Config配置文件使用对称加密的方法
- Spring Cloud Config RSA简介及使用RSA加密配置文件的方法
- 利用Spring Cloud Config结合Bus实现分布式配置中心的步骤
- Spring Cloud Config实现分布式配置中心
- spring-cloud入门之spring-cloud-config(配置中心)
- spring cloud学习教程之config修改配置详解
- spring cloud学习入门之config配置教程
相关文章推荐
- 利用JS中window.showModalDialog()详解
- JQuery上传插件Uploadify使用详解 asp.net版
- http 头信息详解
- JAP 注解详解
- CSS选择器详解(二)通用选择器和高级选择器
- JQuery中$.ajax()方法参数详解
- 【书摘001】android 底层开发技术实战详解 - 基础 - 进程管理的一些常用命令
- 数据库范式(1NF 2NF 3NF BCNF)详解二
- glFinish()和glFlush()函数详解
- Android中attr自定义属性详解
- linux dmesg命令参数及用法详解(linux显示开机信息命令)
- jQuery选择器详解及实例---《转载》
- Console命令详解,让调试js代码变得更简单
- linux vmstat命令详解
- socket编程详解
- System.getProperty()方法获取系统属性详解
- block定义详解
- sizeof与offsetof有关的结构体详解
- 【转载】oracle之rowid详解
- <转载>深入学习JavaScript: apply 方法 详解