美文网首页
SpringCloud-笔记6-统一配置中心git配置yml-s

SpringCloud-笔记6-统一配置中心git配置yml-s

作者: 牵手生活 | 来源:发表于2019-11-18 19:18 被阅读0次

统一配置中心的目的

  • 方便维护
  • 配置内容安全
  • 更新配置项目不需要重启(重点)

统一配置中心包括

  • config-server 配置服务端:为多个微服务服务(如product服务、order服务)
  • config-client 配置客户端
统一配置中心拓扑结构

启动好eurekaserver的module

#确保eureka 服务访问正常
http://localhost:8761/eureka/

在gitee上创建一个项目,并把wechatMsgSns模块的配置放上去wechatMsgSns.yml(原来是application.yml中的内容)

gitee上的配置

在gitee上创建一个项目,并把wechatMsgSns模块的配置放上去wechatMsgSns-test.yml

wechatMsgSns-test

config service (在idea原有项目上创建新module或项目)

新建config的module

需要向Eureka服务进行注册,所有需要导入Eureka的客服端包;
作为config server 所有需要引入config的server端

引入包选择

application.properties改名为application.yml(直接改名)

在启动类添加注解

@EnableDiscoveryClient
@EnableConfigServer //需要配置git的配合,git地址用户、密码在.yml文件中
config服务添加eureka 客户端

application.yml 配置信息

eureka:
  client:
    service-url:
      #多台Eureka服务用“,”隔开
      #注意在:后面一定要有个空格,否则让你怀疑人生
      defaultZone: http://localhost:8761/eureka/ #,http://localhost:8762/eureka/,http://localhost:8763/eureka/
spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/younghare112/config-repo.git
          username: 1483888888@qq.com
          password: nidemimi2000
          #basedir: c:/wechatTask/msgsns/config
yml的配置

运行moduel可以看到Eureka服务已经注册上来


Eureka服务上已经有config的服务

访问可以查看配置的信息

#host:端口/{lable}/git上的{profile}.yml文件
# /{name}-{profiles}.yml
# {lable}/{name}-{profile}.yml
# name :服务名
# profiles :环境
# lable :分支branch(默认master分支)

http://localhost:8080/wechatMsgSns-a.yml
#或
http://localhost:8080/wechatMsgSns-b.yml
#或
http://localhost:8080/wechatMsgSns-b.properties
#或
http://localhost:8080/wechatMsgSns-b.json
或
http://localhost:8080/wechatMsgSns-test.yml

注册中心&配置中心运行状态 访问的不同结果

相关文章

网友评论

      本文标题:SpringCloud-笔记6-统一配置中心git配置yml-s

      本文链接:https://www.haomeiwen.com/subject/hxxpyctx.html