温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

SpringCloud配置中心Config过程解析

发布时间:2020-10-08 08:50:05 来源:脚本之家 阅读:135 作者:玉天恒 栏目:编程语言

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
@EnableConfigServer
public class ConfigServiceApplication {

  public static void main(String[] args) {
    SpringApplication.run(ConfigServiceApplication.class, args);
  }

}

4.修改application.yml配置

server:
 port: 9100
eureka:
 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.在码云服务器新建仓库和文件

SpringCloud配置中心Config过程解析

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分支

另附:

SpringCloud配置中心Config过程解析

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI