当前位置:网站首页>[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
边栏推荐
- 《Dynamic Routing Between Capsules》论文学习总结
- Anti leakage family photo in attack and defense drill
- Five years after graduation, I wondered if I would still be so anxious if I hadn't taken the test
- 本地浏览器打开远程服务器上的Jupyter Notebook/Lab以及常见问题&设置
- Installing jupyter notebook under Anaconda
- 周少剑,很少见
- 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
- 兴奋神经递质——谷氨酸与大脑健康
- The programmer's girlfriend gave me a fatigue driving test
- Niubi | the tools I have treasured for many years have made me free to fish with pay
猜你喜欢

pytorch geometric torch-scatter和torch-sparse安装报错问题解决

Error reporting: internal error XFS_ WANT_ CORRUPTED_ GOTO at line 1635 of file fs/xfs/libxfs/xfs_ alloc. c.

牛逼|珍藏多年的工具让我实现了带薪摸鱼自由

Phoenix architecture: an architect's perspective

1-2 安装并配置MySQL相关的软件

Anfulai embedded weekly report no. 270: June 13, 2022 to June 19, 2022

Installing jupyter notebook under Anaconda

Rethink healthy diet based on intestinal microbiome

《安富莱嵌入式周报》第271期:2022.06.20--2022.06.26

全面认识痛风:症状、风险因素、发病机理及管理
随机推荐
1-20 预检请求
[backtracking] full arrangement II leetcode47
Five years after graduation, I wondered if I would still be so anxious if I hadn't taken the test
1-10 根据不同的url响应客户端的内容
Notes [introduction to JUC package and future]
Pytorch quantitative practice (1)
1-16 路由的概念
Analysis of PostgreSQL storage structure
1-18 create the most basic express server & API module for creating routes
PostgreSQL存储结构浅析
Anaconda下安装Jupyter notebook
1-11 创建线上文件服务
用yml文件进行conda迁移环境时的报错小结
1-1 basic concepts of database
About, Qianxin detects code vulnerabilities and XSS series solves them
Some problems when SSH default port is not 22
Installing jupyter notebook under Anaconda
Uniapp life cycle / route jump
艾芬医生事件解析
Interesting plug-ins summary