NACOS is a dynamic service discovery, configuration management and service management platform that is easier to build cloud primary applications. This time you come to experience NACOS and SpringBoot integration.
Prerequisites: Install Docker, Docker-Compose, Git, if you don't have installed, please check
CoderQiPublic number article
Clone project
git clone https://github.com/nacos-group/nacos-docker.git
// If the above address is slow, please use the following address.
git clone https://gitee.com/amoqi/nacos-docker.git
cd nacos-docker
The directory is as follows
.
├── build
│ ├── bin
│ ├── conf
│ ├── Dockerfile
│ └── init.d
├── changlog
├── env
│ ├── mysql.env
│ ├── nacos-embedded.env
│ ├── nacos-hostname.env
│ ├── nacos-ip.env
│ └── nacos-standlone-mysql.env
├── example
│ ├── cluster-embedded.yaml
│ ├── cluster-hostname.yaml
│ ├── cluster-ip.yaml
│ ├── init.d
│ ├── mysql
│ ├── prometheus
│ ├── standalone-derby.yaml
│ ├── standalone-logs
│ ├── standalone-mysql-5.7.yaml
│ └── standalone-mysql-8.yaml
├── README.md
└── README_ZH.md
Enter the command to modify the mirror version of the NACOS, now you need NACOS to set the mirror version to start.
vi example/standalone-mysql-5.7.yaml
/ / Modify one line below
image: nacos/nacos-server:${NACOS_VERSION}
/ / Change to the following version number, pay attention only to change the version number, the front space is not
image: nacos/nacos-server:1.4.2
Enter the following command to start
docker-compose -f example/standalone-mysql-5.7.yaml up -d
Enter the address after startup View:
http: // ip address: 8848 / NACOS /
Create a springboot project Spring-boot-nacos, POM relies on the following
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--nacos-->
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>${nacos-config-spring-boot.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-actuator</artifactId>
<version>${nacos-config-spring-boot.version}</version>
</dependency>
Configure Application.yml,server-addrAddress + IP for NACOS
spring:
application:
name: spirngboot-nacos
nacos:
config:
server-addr: 192.168.67.68:8848
management:
endpoints:
web:
exposure:
include: always
endpoint:
health:
show-details: always
Enter the NACOS configuration, click on the list of the configuration, add a configuration, as shown

Add annotations on the startup fileNacosPropertySource
@SpringBootApplication
@NacosPropertySource(dataId = "example", autoRefreshed = true)
public class SpringBootNacosApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootNacosApplication.class, args);
}
}
Create a configController.java file, as follows
@Controller
@RequestMapping("config")
public class ConfigController{
// @Value("${useLocalCache:false}")
@NacosValue(value = "${useLocalCache:false}",autoRefreshed = true)
private boolean useLocalCache;
@RequestMapping(value = "/get")
@ResponseBody
public boolean get() {
return useLocalCache;
}
}
Visithttp://localhost:8080/config/getWill show the value of UserCalcache

Enter NACOS, edit the Example file, modify false, as follows
useLocalCache:true
Visithttp://localhost:8080/config/getIt will show uselocalcache as a modified value.

The code word is not easy, I hope to support more. A four-year experience in work experience, currently engaged in the work of logistics industries, has its own small breaking website amoqi.cn. Welcome everyone to pay attention to the public number [CODERQI] to exchange Java knowledge, including but not limited to Springboot + micro service, there is more video, interview materials and professional books, etc. during the Qiqi learning process, I hope everyone can like it.

Configuration Center Introduction background analysis We know, in addition to the code, the software has some configuration information, such as the username and password of the database, and some we ...
What is the configuration center? The most basic function of the configuration center is to store a key value pair, the user releases a configuration (configkey), and then the client obtains the confi...
Table of contents Configuration Center Introduction background analysis Overview of the configuration center Mainstream configuration center Small interview analysis NACOS configuration quickly get st...
NACOS Service Configuration Center Application Practice Articles directory NACOS Service Configuration Center Application Practice Introduction to the configuration center 1.1 Background Analysis 1.2 ...
The REDIS of the code can be deleted, mainly in file monitoring and file loading these places. Controller layer Service layer Write file listener Set monitoring factory Set file monitor self-start...
Introduction Starting from spring, all configuration files are placed in the project. If you need to modify the contents of the configuration file, you need to log in to the server to restart the serv...
Install nacos service in docker and start pull the latest version Visit "ip: 8848/navos" to enter the management interface Account password are all Nacos 2. New namespace 3. Create a ...
1. Guide SpringCloudalibaba version dependency manager 2. Guide NACOS 3. Adjubes in the startup class 4. Configuration...
SpringBoot+Nacos Dynamic changes to the configuration through NaCOS Server and Spring-Cloud-Starter-Alibaba-Nacos-Config. Registration and discovery of service through NaCOS Server and Spring-Cloud-St...
First, NACOS introduction What is NACOS? Simple point, NACOS has two core functions: Manage micro service In the case of too many micro services, a unified management scheduling system is needed. Do a...