1. springcloud 分布式的问题 application.yml文件太多了
配置要整和在一起更加方便管理
springcloud config
- springcloud config时为管理微服务提出的一套集中化的配置
可以将数据放到本地和远程 - 微服务默认采用git方式放在云端 进行管理 有助于团队协作进行测试.
- 能干嘛
- 集中式的管理
- 不同环境 不同配置 动态化更新 分布环境部署 必然要 /test /dev …
- 运行期间动态获取配置信息 不需要在每个微服务上面去修改配置文件 服务会向配置中心统一拉取自己需要的配置信息
- 当配置发生变动时 服务不需要重启 即可感知配置变化 并且自动更新配置
- 将配置信息以Rest风格接口暴露出来(流弊)
- 需要将代码托管到其他品台 (github 或 码云)
git 信息 详解 专业的就是不一样
1.测试 编写 yml 服务端
server:
port: 3344
spring:
config:
name: config-server
##连接远程仓库
cloud:
config:
server:
git:
uri: https://gitee.com/gitgethub/springcloudconfig.git #https 不是ssh
##通过config server 我们连接到git上面的yml配置
- 开启服务@EnableConfigServer
- 访问
- 本机git到项目的方法
git add . //获取更新
git commit -m “注释”
git push origin master //更新到当前master下 - 远程配置yml 要写为bootstrop中 因为application.yml是用户级别的 ,bootstrap.yml是系统级别的减少矛盾 设置一个model类远程连接 连接到git 托管平台 然后eureka子项目连接到主连接的model 如下 配置在bootstrap.yml中
spring:
cloud:
config:
name: springcloud-dept-8003 #连接git网络的名称 不带.yml
label: master #连接项目的名称
profile: dev #启用的模块
uri: http://localhost:3344 #在这个端口进行配置连接git远程
localshot:3344 配置
server:
port: 3344
spring:
config:
name: config-server
##连接远程仓库
cloud:
config:
server:
git:
uri: https://gitee.com/gitgethub/springcloudconfig.git #https 不是ssh
##通过config server 我们连接到git上面的yml配置
现在基于能将代码托管到git平台了 流弊
GIt操作
git branch //查看所有分支