分布式配置中心

一、创建 ConfigServer服务端

1、 登录 Gitee(码云)或者 Github 创建项目,上传配置文件 config-client-dev.properties
注意:配置文件名称与分布式配置中心客户端的项目应用名称保持一致,规则如下:{application}-
{profile}.properties在这里插入图片描述
2、 创建一个 SpringBoot 项目,配置成为一个分布式配置中心的服务端。需要在 pom 文件中加入依赖 springcloud-config-server

		<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
            <version>2.2.5.RELEASE</version>
        </dependency>

3、 项目配置文件中配置 Gitee(码云)或者 Github,项目中配置文件的信息如下:application.yml
注意:git如果创建时选择的是私有时需要在配置中加上账号密码
spring.cloud.config.server.git.username=账号
spring.cloud.config.server.git.password=密码

server:
  #项目发布端口号
  port: 7100
spring:
  application:
    #项目应用注册名称
    name: cloud-config7100
  cloud:
    config:
      server:
        git:
          #远程 Git 项目仓库地址
          uri: https://gitee.com/lsjwill/springcloud-demo.git

4、 在项目入口函数使用注解@EnableConfigServer 启用分布式配置中心服务,启动服务
通过浏览器访问配置文件,访问规则如下

URL 规则: /{application}/{profile}[/{label}]
在这里插入图片描述

二、创建 ConfigClient

1、 创建一个 SpringBoot 项目,加入配置中心客户端依赖 spring-cloud-starter-config

		<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

2、项目配置文件 bootstrap.properties 配置分布式配置中心服务端 bootstrap.yml

spring:
  cloud:
    config:
      #项目应用注册名称(MS:Git 仓库配置文件中 application 与此处对应)
      name: demo-eureka
      #多环境配置,默认 default(MS:Git 仓库配置文件中 profile 与此处对应)
      profile: dev
      #远程 Git 项目仓库分支
      label: master
      #分布式配置服务地址
      uri: http://localhost:7100

3、 启动项目,访问 http://localhost:9001/getConfig

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值