Spring Cloud Consul高级配置实战

一 代码位置

https://github.com/cakin24/spring-cloud-code/tree/master/ch14-3

二 启动consul

consul agent -dev -ui

三 客户端配置

spring:
  application:
    name: consul-config-customize
  cloud:
    consul:
      config:
        format: yaml              # Consul 中 Value 配置格式为 yaml
        prefix: configuration     # Consul 中配置文件目录为 configuration, 默认为 config
        default-context: app      # 去该目录下查找缺省配置,默认为 application
        profile-separator: ':'    # profiles配置分隔符,默认为‘,’
        data-key: data            # 如果指定配置格式为 yaml 或者 properties, 则需要该值作为key,默认为 data

四 在Consul的配置页面配置如下数据

按照同样的方式再配置一条数据

foo:
  bar:
    name: cakin_test
server:
  port: 8083

注意上面输入时用空格,不要用Tab键,否则启动consul-config-customize会报错。

五 测试 

1 启动consul-config-customize

2019-11-24 14:51:56.624  INFO 17576 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8083 (http)
2019-11-24 14:51:56.661  INFO 17576 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]

启动了Consul的8083端口

2 浏览器输入:http://localhost:8083/getName

高级配置生效。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值