SpringCloud配置中心Config过程解析

时间:2021-05-19

1.什么是配置中心

统一管理配置,怏速切换各个环境的配置

相关产品:

百度的 discont

  https://github.com/knightliao/disconf

阿里的diamand

  https://github.com/takeseem/diamond

springcloud的configs-server:

  http://cloud.spring.io/spring-cloud-config/

2.添加依赖

<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.启动类添加注解@EnableConfigServer

import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.config.server.EnableConfigServer;@SpringBootApplication@EnableConfigServerpublic class ConfigServiceApplication { public static void main(String[] args) { SpringApplication.run(ConfigServiceApplication.class, args); }}

4.修改application.yml配置

server: port: 9100eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/spring: application: name: config-server cloud: config: server: git: #仓库地址,去掉git uri: https://gitee.com/YTHeng/config_cloud #git服务器登录的用户名和密码,我这边使用的是码云 username: 12345678@qq.com password: 12345678. #超时时间 timeout: 5 #分支 default-label: master

5.在码云服务器新建仓库和文件

6.访问地址

http://localhost:9100/master/product-service-dev.yml

路径访问方式

/{name}-{profiles}. properties
/{name}-{profiles}.yml
/{name}-{profiles}.json
/{label}/{name]-{profiles].yml

name:服务器名称

profile:环境名称,开发、测试、生产

Lable:仓库分支、默认 master分支

另附:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章