基于上一篇文章的项目实现:https://www.jianshu.com/p/e11ff097424b
一、运行nacos
nacos官网https://nacos.io下载即可
运行,访问:http://127.0.0.1:8848/nacos/index.html账号密码都是nacos
添加一个配置
将配置填写后,右下角的发布按钮:
image.png
在消费者的
pom.xml
加入依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>0.9.0.RELEASE</version>
</dependency>
删除application.yml
配置,添加bootstrap.properties
:
#名称对上nacos创建的 consumer,注意此处少了后缀 .yaml
spring.application.name=consumer
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
spring.cloud.nacos.config.file-extension=yaml
完成上述两步后,应用会从 Nacos Config 中获取相应的配置,并添加在 Spring Environment 的 PropertySources 中,在controller中添加:
image.png
1、启动生产者
2、启动消费者
访问http://localhost:8080/sayHi/lingkang
然后在nacos改下值:
image.png
image.png
网友评论