当前位置:网站首页>[micro service ~nacos] configuration center of Nacos
[micro service ~nacos] configuration center of Nacos
2022-06-30 22:01:00 【Classmate Tao Ran】

Here is 【 Microservices ~Nacos】, Pay attention to my learning cloud and don't get lost
If it helps you , Give the blogger a free praise to show encouragement
You are welcome to comment on the collection ️
Column introduction
【 Microservices ~Nacos】 At present, it mainly updates micro services , Learn together and progress together .
Introduction to this issue
This issue mainly introduces micro services ~Nacos
List of articles
How much do you know about integration
Build services
Project name :nacos-config-2.1
Add coordinates :

<dependencies>
<!-- web starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- nacos Service discovery -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- nacos To configure -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
</dependencies>
- establish yml The configuration file :bootstrap.yml

server:
port: 8072 # Port number
spring:
application:
name: config-service # service name
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848 # nacos Service address
prefix: ${spring.application.name} #data ID The prefix of , Default service name
file-extension: yaml # data ID The suffix :config-service.yaml
group: DEFAULT_GROUP # Group name
discovery:
server-addr: 127.0.0.1:8848 #nacos Service address
Create services
- Write the startup class

package com.czxy.nacos;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestNacosCloudConfigApplication {
public static void main(String[] args) {
SpringApplication.run(TestNacosCloudConfigApplication.class, args);
}
}
- Write processing class

package com.czxy.nacos.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/config")
@RefreshScope
public class ConfigController {
@Value("${czxy.message:' The default value is '}")
private String msg;
/**
* http://localhost:8072/config/get
*/
@RequestMapping("/get")
public String get() {
return msg;
}
}
Query service
situation 1, visit “ Default data ”
http://localhost:8072/config/get

- situation 2, visit yml File configuration information
czxy:
message: Test data 
- situation 3: visit nacos Configuration data in


How much do you know about integration
stay Nacos Spring Cloud in ,
dataIdThe complete format is as follows
${prefix}-${spring.profile.active}.${file-extension}
Show profile Data in
1) To write profile:application-demo.yml

server:
port: 8073 # Port number
czxy:
message: demo data 2) Modify the boot entry
-Dspring.profiles.active=demo

3) Delete nacos After the configuration , test

nacos The default configuration
1)nacos To configure
config-service.yamlOf Data ID

2) test

nacos To configure profile
1) To configure nacos profile :
config-service-demo.yaml

2) test

nacos Profile load order
spring boot、nacos Loading order of various configuration files
1.bootstrap.yml
2.application.yml
3.application-[profile].yml
4.[serviceName].yml #nacos To configure
5.[serviceName]-[profile].yml #nacos To configure
Files loaded later , The configuration contents of the previous file will be overwritten
边栏推荐
- 1-1 数据库的基本概念
- AKK菌——下一代有益菌
- 【MySQL入门】第一话 · 初入“数据库”大陆
- 顺祝老吴的聚会
- Is Wu Enda's machine learning suitable for entry?
- Summary of errors reported when using YML file to migrate CONDA environment
- Nacos部署及使用
- The Jenkins download Plug-in can't be downloaded. Solution
- Five years after graduation, I wondered if I would still be so anxious if I hadn't taken the test
- 介绍一款|用于多组学整合和网络可视化分析的在线平台
猜你喜欢

介绍一款|用于多组学整合和网络可视化分析的在线平台

jenkins下载插件下载不了,解决办法

Summary of errors reported when using YML file to migrate CONDA environment

兴奋神经递质——谷氨酸与大脑健康

Which direction should college students choose to find jobs after graduation?

Is Wu Enda's machine learning suitable for entry?

机器学习工作要求研究生吗?

Is there a shortage? No need to download the free online resources! 2022 favorites must have it!

Akk bacteria - the next generation of beneficial bacteria

pytorch geometric torch-scatter和torch-sparse安装报错问题解决
随机推荐
Neurotransmetteurs excitateurs - glutamate et santé cérébrale
Pytorch quantitative perception training (qat) steps
Modify the name of the launched applet
Is there a shortage? No need to download the free online resources! 2022 favorites must have it!
Qsort function and Simulation Implementation of qsort function
1-17 express中间件
Akk bacteria - the next generation of beneficial bacteria
1-13 express监听GET和POST请求&处理请求
jenkins下载插件下载不了,解决办法
Is the stock account opened in qiniu safe? How to apply for a low commission stock account?
pytorch geometric torch-scatter和torch-sparse安装报错问题解决
1-19 利用CORS解决接口跨域问题
阿婆做的臭豆腐
1-10 根据不同的url响应客户端的内容
Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
Rethink healthy diet based on intestinal microbiome
1-3 using SQL to manage databases
Vite2 is compatible with lower versions of chrome (such as Sogou 80). Some grammars requiring higher versions are processed through polyfills
从PG15 XID64再次跳票说起
Notes [introduction to JUC package and future]