当前位置:网站首页>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,否则配置文件修改,工程无法感知

边栏推荐
猜你喜欢

Baidu promotion assistant encounters duplicate keywords, verification errors, how to delete redundant ones with one click

ThreadLocal内存泄漏是伪命题?

HR团队如何提升效率?人力资源RPA给你答案

Re15:读论文 LEVEN: A Large-Scale Chinese Legal Event Detection Dataset

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

Re16:读论文 ILDC for CJPE: Indian Legal Documents Corpus for Court Judgment Prediction and Explanation

JCL 学习

nacos实战项目中的配置

国外资源加速下载器,代码全部开源

ospf2双点双向重发布(题2)
随机推荐
flowable workflow all business concepts
debian10安装djando
leetcode 剑指 Offer 42. 连续子数组的最大和
多线程保证单个线程开启事务并生效的方案
通过构建一个顺序表——教你计算时间复杂度和空间复杂度(含递归)
A near-perfect Unity full-platform hot update solution
Re17:读论文 Challenges for Information Extraction from Dialogue in Criminal Law
In 2022, the top will be accepted cca shut the list
leetcode 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
BERT pre-training model series summary
hcip06 ospf special area comprehensive experiment
百度推广助手遇到重复关键字,验证错误,怎么一键删除多余的
Re21:读论文 MSJudge Legal Judgment Prediction with Multi-Stage Case Representation Learning in the Real
HR团队如何提升效率?人力资源RPA给你答案
多线程--线程和线程池的用法
Shell系统学习之函数
The use of qsort function and its analog implementation
Four ways the Metaverse is changing the way humans work
Baidu promotion assistant encounters duplicate keywords, verification errors, how to delete redundant ones with one click
时刻铭记:总有一天你将破蛹而出