当前位置:网站首页>Nacos Configuration Center
Nacos Configuration Center
2022-07-30 03:32:00 【Leon_Jinhai_Sun】
We learned SpringCloud Config earlier, we can load remote configuration by configuring service, so that we can centrally manage configuration files at the remote end.
Actually, we can configure remote configuration file acquisition in bootstrap.yml, and then enter the configuration file loading link, and Nacos also supports this operation, and the way of use is alsoSimilar, for example, we now want to put the configuration file of the borrowing service in Nacos for management, then we need to create a configuration file in Nacos at this time:

Copy all the configuration files of the borrowing service (of course, not all CVs under normal circumstances, only those parts that need to be modified frequently, here are all CVs to save trouble) Copy over, pay attentionThe format of Data ID is the same as before, application name-environment.yml, if only the application name is written, it means that this configuration file will be used no matter what environment it is in, and thenEach configuration file can be grouped, which can be regarded as a kind of classification:

Click publish when finished:

Then import the dependencies in the project:
org.springframework.cloud spring-cloud-starter-bootstrap com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config Then we add the bootstrap.yml file to the borrowing service:
spring:application:# Keep the service name and configuration file the samename: borrowserviceprofiles:# The environment is also consistent with the configuration fileactive: devcloud:nacos:config:# Configuration file suffixfile-extension: yml# Configure the center server address, which is the Nacos addressserver-addr: localhost:8848Now let's start the service and try:

You can see that the configuration file was successfully read and started. In fact, it is basically the same as the previous Config.
Nacos also supports hot update of configuration files. For example, we have added an attribute to the configuration file, and this time may need to be modified in real time and updated in real time at the back end, so how to achieve this??We create a new Controller:
@RestControllerpublic class TestController {@Value("${test.txt}") //We read the string value of test.txt from the configuration file as the return value of the test interfaceString txt;@RequestMapping("/test")public String test(){return txt;}}Let's modify the configuration file and restart the server:

You can see that it can be read normally:

Now we will modify the value of the configuration file:

Access the interface again and you will find that there is no change:

But the background successfully detected that the value was updated, but the value did not change:

Then how to achieve configuration hot update?We can do something like this:
@[email protected] //Add this annotation to achieve automatic refreshpublic class TestController {@Value("${test.txt}")String txt;@RequestMapping("/test")public String test(){return txt;}}Restart the server and repeat the above experiment again, it is successful.
边栏推荐
- 记录NLP各种资源网址
- Overview of Federated Learning (2) - Classification, Framework and Future Research Directions of Federated Learning
- [3D检测系列-PointRCNN]复现PointRCNN代码,并实现PointRCNN3D目标检测可视化,包含预训练权重下载链接(从0开始以及各种报错的解决方法)
- MyCat中对分库分表、ER表、全局表、分片规则、全局序列等的实现与基本使用操作
- 北京bgp机房和普通机房的区别
- golang的channel实现原理
- First acquaintance with the web
- TCP拥塞控制技术 与BBR的加速原理
- C# 一周入门之《C#-类和对象》Day Six
- 【SQL】按某个关联列用一张表的数据更新另一张表
猜你喜欢
随机推荐
VMware磁盘扩容记录
Stimulsoft ReportsJS and DashboardsJS. 2022.3.3
还在用命令行看日志?快用Kibana吧,可视化日志分析YYDS
JUC (5): Problems caused by sharing
雪花是否一样问题
传输层详解
OpenFeign realize load balance
NLP自然语言处理(一)
自定义 View 实现汉字笔顺动画
【Use of scientific research tools】A
路由过滤器
联邦学习综述(一)——联邦学习的背景、定义及价值
Software testing interview questions and answer analysis, the strongest version in 2022
JUC (four): five/six states of shorthand thread
精品:淘宝/天猫获取购买到的商品订单详情 API
写给技术人的管理入门知识1:什么是管理
答对这3个面试问题,薪资直涨20K
nSoftware.PowerShell.Server.2020
golang的channel实现原理
JIT vs AOT






![[C Supplement] Conversion of Integer to String](/img/61/4261ea9bf3001dfa8deed424fce145.jpg)


