Springboot integrated NACOS configuration center and dynamic configuration

tags: java  nacos  Springboot

Brief description

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.

Download Nacos

Please click on the following URL yet to download

Nacos download point me

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

Springboot Add NACOS Dependent

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>

Configuring NACOS in Application.yml

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.

Startup configuration

@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

Test data by MVC (Controller)

@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

Postman test

Change NACOS configuration

Change the configuration from V1.0 to v1.1

Postman test [Do not restart the Springboot project]

Dynamic configuration

The @nacosvalue annotation has an attribute to control whether it is dynamically updated to configure autorefreeshed = true

Intelligent Recommendation

springboot configuration center-nacos

Add dependency Add configuration Get configuration business code nacos service configuration...

SpringBoot + Nacos Configuration Center

SpringBoot + Nacos Configuration Center Introducing dependence in the POM file 2. Profile This will be read to the file of the NACOS configuration center....

springboot+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

springboot configuration-integrated nacos Article Directory springboot configuration-integrated nacos 1. Installation information 2. Configuration release and acquisition 3. Service Registration and C...

SpringCloud integrated NACOS configuration center

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...

More Recommendation

Seata Integrated NACOS Configuration Center

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...

SpringCloud integrated NACOS as a configuration center

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...

Spring/springboot integrated distributed configuration center (ACM diamond nacos Apollo)

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...

Spring Cloud Alibaba Tutorial Series, SpringBoot Integrated NACOS Configuration Center

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...

SpringCloud + SpringBoot integrated NACOS Make Configuration Center Mode 2 [2]

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...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top