当前位置:网站首页>Nacos configuration in the project of battle
Nacos configuration in the project of battle
2022-07-30 10:14:00 【Fairy to carry】
目录
场景:Build a cluster like this,The configuration file used by multiple nodes is definitely similar,So we can read our configuration files in the configuration center,或者说,Use the idea of variable separation, 开发者通常会将一些需要变更的参数、变量等从代码中分离出来独立管理,以独立的配置文件的形式存在.目的是让静态的系统工件或者交付物(如 WAR,JAR 包等)更好地和实际的物理运行环境进行适配.
There is no common problem with Unified Configuration Center:
- 配置文件分散在各个项目里,不方便维护
- 配置内容安全与权限
- 更新配置后,项目需要重启
nacos配置中心:系统配置的集中管理(编辑、存储、分发)、动态更新不重启、回滚配置(变更管理、历史版本管理、变更审计)等所有与配置相关的活动.

读取nacos配置文件
1.Create first

2.输入配置信息
${prefix}-${spring.profile.active}.${file-extension}
服务名称-dev环境.File extension type

springBoot配置文件加载顺序
这里主要是说明application和bootstrap的加载顺序.
1.bootstrap.yml(bootstrap.properties)先加载
2.application.yml(application.properties)后加载
bootstrap.yml 用于应用程序上下文的引导阶段.
bootstrap.yml 由父Spring ApplicationContext加载.
父ApplicationContext 被加载到使用 application.yml 的之前.
If the environment is configured
spring.profiles.active=dev——>就会加载application-dev.properties文件
bootstrap和application的区别
bootstrap.yml 和application.yml 都可以用来配置参数.
bootstrap.yml 可以理解成系统级别的一些参数配置,这些参数一般是不会变动的.
application.yml 可以用来定义应用级别的.
修改bootstrap.properties配置文件
里面的配置的dataIdIt is a node of the configuration center
#配置中心地址
spring.cloud.nacos.config.server-addr=82.157.198.247:8848
#spring.profiles.active=dev
# 该配置影响统一配置中心中的dataId
spring.application.name=service-statistics导入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
命名空间切换->配置不同环境的配置文件


Practice switching between different namespaces

Then go to the configuration list to see
Can be cloned into other environments

We can specify which environment is in the configuration file

Then in servicebootstrap中进行修改,Add the specified environment namespace
Multi-file configuration read
1. 在生产devConfigure two configuration files in the environment

2.Then again in servicebootstrap文件中进行配置,Read multiple configuration files
Remember to enable dynamic refresh configuration,否则配置文件修改,工程无法感知

边栏推荐
猜你喜欢
容器技术 -- 简单了解 Kubernetes 的对象

leetcode 剑指 Offer 63. 股票的最大利润

Practical Walkthrough | Calculate Daily Average Date or Time Interval in MySQL

leetcode 剑指 Offer 25. 合并两个排序的链表

Unified exception handling causes ResponseBodyAdvice to fail

leetcode 剑指 Offer 48. 最长不含重复字符的子字符串

线上靶机prompt.ml

Do you really understand the 5 basic data structures of Redis?

Re18: Read the paper GCI Everything Has a Cause: Leveraging Causal Inference in Legal Text Analysis

JVM内存布局、类加载机制及垃圾回收机制详解
随机推荐
PyQt5-用像素点绘制正弦曲线
Matplotlib--绘图标记
leetcode 剑指 Offer 42. 连续子数组的最大和
In 2022, the top will be accepted cca shut the list
leetcode 剑指 Offer 58 - I. 翻转单词顺序
阿里云OSS对象存储
唯物辩证法-条件论
时刻铭记:总有一天你将破蛹而出
快解析结合象过河erp
元宇宙改变人类工作模式的四种方式
debian10 install djando
通过构建一个顺序表——教你计算时间复杂度和空间复杂度(含递归)
The thread pool method opens the thread -- the difference between submit() and execute()
leetcode 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
软考 系统架构设计师 简明教程 | 系统运行与软件维护
Study Notes 10--Main Methods of Local Trajectory Generation
Always remember: one day you will emerge from the chrysalis
In the robot industry professionals, Mr Robot industry current situation?
leetcode 剑指 Offer 52. 两个链表的第一个公共节点
在机器人行业的专业人士眼里,机器人行业目前的情况如何?