当前位置:网站首页>使用Nacos管理配置
使用Nacos管理配置
2022-07-06 06:08:00 【雪峰.贵】
文章目录
一、加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
二、约定
箭头连接的两端要一致,微服务里是一个bootstrap.yml,对应Nacos上多个指定环境的配置。微服务启动时指定active,就会去Nacos上找相应环境的配置。
三、bootstrap.yml
spring:
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848
file-extension: yaml
application:
name: content-center
profiles:
active: dev
四、加配置
此时这个配置就已经配置到了开发环境
五、业务代码取配置
@Value("${your.config}")
private String config;
六、@RefreshScope
在获取配置的类上加上注解,就能动态的获取Nacos配置.
七、回滚配置
八、一个微服务通用配置
1. 所有环境的通用配置写在:{微服务名}.yaml中
2.yaml的优先级:
指定profile的yaml > {微服务名}.yaml
九、不同微服务的配置共享
ext-config方式
spring:
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848
file-extension: yaml
ext-config:
# 需共享的DataId,yaml后缀不能少,只支持yaml/properties
# 越靠后,优先级越高 优先级common2.yaml > common1.yaml
- data-id: common1.yaml
# common1.yaml所在的group
group: DEFAULT_GROUP
# 是否允许刷新,默认false
refresh: true
- data-id: common2.yaml
group: DEFAULT_GROUP
refresh: true
application:
name: content-center
profiles:
active: dev
shared-dataids方式
spring:
cloud:
nacos:
config:
# 共享配置的DataId,多个使用,分隔
# 越靠后,优先级越高;common2.yml > common1.yaml
# .yaml后缀不能少,只支持yaml/properties
shared-dataids: common1.yaml,common2.yaml
# 哪些共享配置支持动态刷新,多个使用,分隔
refreshable-dataids: common1.yaml
server-addr: 127.0.0.1:8848
file-extension: yaml
application:
name: content-center
profiles:
active: dev
只需将两种方式的代码复制到bootstrap里,并在Nacos上相应的组里配置common1.yaml,common2.yaml即可。
十、远程配置与本地配置优先级
默认Nacos上的配置>application.yml & bootstrap.yml
也可在Nacos上的某个配置文件修改优先级
边栏推荐
- ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
- 数字三角形模型 AcWing 1015. 摘花生
- Company video accelerated playback
- 【API接口工具】postman-界面使用介绍
- MPLS test report
- 【Postman】动态变量(也称Mock函数)
- 10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Gtest之TEST宏的用法
- isam2运行流程
猜你喜欢
Buuctf-[gxyctf2019] no dolls (xiaoyute detailed explanation)
H3C firewall rbm+vrrp networking configuration
Significance of unit testing
【C语言】字符串左旋
ContentType的作用
[untitled]
[eolink] PC client installation
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
[postman] test script writing and assertion details
随机推荐
Introduction to promql of # yyds dry goods inventory # Prometheus
About PHP startup, mongodb cannot find the specified module
通过修改style设置打印页样式
H3C S5820V2_ Upgrade method after stacking IRF2 of 5830v2 switch
[postman] test script writing and assertion details
Request forwarding and redirection
[Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
Function of activation function
误差的基本知识
CoordinatorLayout+NestedScrollView+RecyclerView 上拉底部显示不全
Accélération de la lecture vidéo de l'entreprise
Overview of three core areas of Mathematics: algebra
Wib3.0 leapfrogging, in leapfrogging (ง • ̀_•́) ง
Raised a kitten
10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
公司視頻加速播放
Manhattan distance sum - print diamond
Overview of three core areas of Mathematics: geometry
IDEA 新UI使用
What are the test sites for tunnel engineering?