最终成功版。
- 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好使,当然还有源码。