springcloud(5)config server

本文探讨了配置中心在微服务架构中的关键作用,包括解决配置维护不便、安全性及重启需求等问题。通过Spring Cloud Config实现配置的集中管理,介绍了如何配置git仓库作为配置源,以及配置文件的命名规则和访问方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

为什么需要配置中心?
不方便维护
配置内容的安全和配置
更新项目配置需要重启

在这里插入图片描述
在这里插入图片描述

由于config-server 既是eureka的client端,又是config的server端。

在这里插入图片描述

然后我们选用的是https://gitee.com/XXXXXX/order.yml
新建order.yml
在这里插入图片描述

然后配置文件 application.yml

spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/xxxxxxx/config-repo.git
          username: xxx@xx.com
          password: xxxxxx
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

记住这里是spring.cloud.config.git.uri

然后访问http://localhost:8080/order-a.yml
然后就能访问到:
在这里插入图片描述

在这里插入图片描述
http://localhost:8080/order-a.properties

在这里插入图片描述
http://localhost:8080/order-a.json

配置命名的约定规则:
如:
1./order-dev.yml (/文件名-环境名.文件后缀)
2./dev/order-dev.yml (/分支名/文件名-环境名.文件后缀)
每一种都可以用
/{name}-{profiles}.yml
/{label}/{name}-{profiles}.yml
name 服务名
profile 环境
label 分支 branch

其实springcloud config会把远端的git拉到本地的git上来。
在这里插入图片描述

然后可用指定 basedir;再新建个文件夹,不然会被清空:

spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/xxxxx/config-repo.git
          username: xxxxx@xxxx.com
          password: xxxx
          basedir: /Users/xxx/xxxxx/xxx-springcloud-xx/config/basedir
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值