springboot 使用consul 读取配置文件(遇到的坑太多,没记录)

旧巷老猫 提交于 2019-12-05 04:28:09

最终成功版

  1. pom引入mavn依赖:
        <!--consul-->        <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-consul-discovery</artifactId>            <version>2.1.2.RELEASE</version>        </dependency>        <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-consul-config</artifactId>            <version>2.1.2.RELEASE</version>        </dependency>

  2.yml文件:        

spring:  application:    name: demo  cloud:    consul:      config:        data-key: data        prefix: config        format: yaml      host: consul的ip地址      port: 端口      discovery:        prefer-ip-address: trueserver:  port: 8080

 3.启动类添加

@EnableDiscoveryClient 注解,sb2.0以后不需要添加,@EnableAutoConfiguration

4.配置consul,key/value

key:config/demo/data  (demo对应项目名,data对应data-key)

value: 原始sb的yml配置,我的是有缩进的可以读取的,没有缩进没试过。

原文地址:https://blog.csdn.net/weixin_39556804/article/details/93893404

总结一下,看了这么多文章,都是模模糊糊,千篇一律,还是 stackoverflow好使,当然还有源码。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!