tags: java nacos Springboot
Please check the previous article for NACOS in distributedBuilt a SpringCloud-Alibaba framework。
Different distributed and monomer projects are different, and the configuration also goes out. Of course, this article does not include service registration related content, only guides the need to integrate NACOS configuration centers and dynamically configured small partners.
Please click on the following URL yet to download
At present, the latest version is 1.4.1, open the connection above, and pull the compressed package at the bottom, install NACOS will not be explained. To the point
Note: Version 0.2.x.release corresponds to the Spring Boot 2.x version, version 0.1.x.release corresponds to the Spring Boot 1.x version.
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>${your.version}</version>
</dependency>
Here is the difference between NACOS in Spring-Cloud-Alibaba.
Difference 1: Distributed in your configuration needs to be placed in bootstrap, and the monomer project is placed in the Application
Difference 2: DateID, Type, GroupId, etc. in distributed, Type, GroupID, etc. can be disposed in the bootstrap configuration file, while these points mentioned above need to be configured by adding @nacoPropertySource annotations in the startup class. The specific operation is as follows
nacos:
config:
server-addr: 127.0.0.1:8848
namespace: 2e72f4cf-ca30-4a94-9659-d9e42369326e
Note: If Namespace is not configured, the default is pulled from public to PUBLIC.
@SpringBootApplication
@NacosPropertySource(dataId = "examples", type = ConfigType.YAML,groupId = "test",autoRefreshed = true)
public class CheckApplication {
public static void main(String[] args) {
SpringApplication.run(CheckApplication.class, args);
}
}
Corresponding NACOS page


@RestController
public class TestController {
@NacosValue(value = "${test.properties-version}", autoRefreshed = true)
private String propertiesVersion;
@GetMapping("/test/config")
public String propertiesVersion() {
return propertiesVersion;
}
}
Set the value of the property, @nacosvalue and Spring @nacosvalue and Spring here

Change the configuration from V1.0 to v1.1

The @nacosvalue annotation has an attribute to control whether it is dynamically updated to configure autorefreeshed = true
Add dependency Add configuration Get configuration business code nacos service configuration...
SpringBoot + Nacos Configuration Center Introducing dependence in the POM file 2. Profile This will be read to the file of the NACOS configuration center....
Official website nacos download address:Releases · alibaba/nacos · GitHub Start the Nacos service Linux/Unix/Mac Start command (standalone represents standalone running on standalone mod...
springboot configuration-integrated nacos Article Directory springboot configuration-integrated nacos 1. Installation information 2. Configuration release and acquisition 3. Service Registration and C...
First, add dependence Create a bootstrap.yml configuration file and set the registration center address. If NACOS is also used as a registration center, you can also add it. The reason why Spring.Appl...
registry.conf SERVER config.txt Intercept DB related information Upload command related resources nacos-config.sh config.txt Start service registration success Reference documentation NACOS configurat...
Step 1: Pom.xml dependency configuration Note: 2.1.0.Release corresponding, Spring-boot-start-parent: 2.3.5.Release version, Spring-Cloud: HOXTON.SR9 version Step 2: Bootstrap.properties configuration...
Note: This article is a bit long, so I suggest you download the source code to learn. (Please bookmark if necessary! Please declare the source for reprinting, thank you!) Code download:https://gitee.c...
Series article catalog Spring Cloud Alibaba Tutorial Series, SpringBoot Integrated NACOS Configuration Center Article catalog Series article catalog Foreword First, what is NACOS? Second, use steps In...
Configuration Center details Profile named by project name: Test.properties New configuration Create service 1. Introduce dependencies: 2. Creating a configuration file name is bootstrap.yml, pay atte...