当前位置:网站首页>[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-10 根据不同的url响应客户端的内容
- Stimulate new kinetic energy to develop digital economy in multiple places
- 盘点华为云GaussDB(for Redis)六大秒级能力
- About, Qianxin detects code vulnerabilities and XSS series solves them
- Five years after graduation, I wondered if I would still be so anxious if I hadn't taken the test
- Do machine learning jobs require graduate students?
- Anaconda下安装Jupyter notebook
- Alibaba Kube eventer MySQL sink simple usage record
- 1-20 pre inspection request
- The Three Musketeers: One for All!
猜你喜欢

JD and Tencent renewed the three-year strategic cooperation agreement; The starting salary rose to 260000 yuan, and Samsung sk of South Korea scrambled for a raise to retain semiconductor talents; Fir

On several key issues of digital transformation

全面认识痛风:症状、风险因素、发病机理及管理

Prediction and regression of stacking integrated model

Development techniques - import files using easyexcel (simple example)

WinDbg debugging tool introduction

Best wishes for Lao Wu's party

Uniapp life cycle / route jump

Excitatory neurotransmitter glutamate and brain health

1-2 安装并配置MySQL相关的软件
随机推荐
A comprehensive understanding of gout: symptoms, risk factors, pathogenesis and management
[untitled] first time to participate in CSDN activities
Introduction to go web programming: a probe into the excellent test library gocovey
微服务链路风险分析
【回溯】全排列 leetcode46
Which direction should college students choose to find jobs after graduation?
1-17 express中间件
Error reporting: internal error XFS_ WANT_ CORRUPTED_ GOTO at line 1635 of file fs/xfs/libxfs/xfs_ alloc. c.
Do machine learning jobs require graduate students?
艾芬医生事件解析
The programmer's girlfriend gave me a fatigue driving test
jupyter notebook/lab 切换conda环境
国产数据库乱象
Jupyterbook clear console output
Alibaba Kube eventer MySQL sink simple usage record
Rethink healthy diet based on intestinal microbiome
牛逼|珍藏多年的工具让我实现了带薪摸鱼自由
机器学习中如何使用数据集?
程序员女友给我做了一个疲劳驾驶检测
Ml & DL: introduction to hyperparametric optimization in machine learning and deep learning, evaluation index, over fitting phenomenon, and detailed introduction to commonly used parameter adjustment