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


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

被折叠的 条评论
为什么被折叠?



