All Products
Search
Document Center

Microservices Engine:Integrate an MSE Nacos configuration center with Spring Cloud applications

Last Updated:Dec 18, 2025

This topic describes how to integrate a Microservices Governance (MSE) Nacos configuration center with Spring Cloud applications. This helps implement centralized configuration management and dynamic refresh for the applications.

Background information

In a microservices architecture, a large number of microservice application instances are deployed across multiple environments, such as development, test, and production environments. The hard-coded or static configuration files of the instances are managed in the traditional manner. This causes issues such as configuration inconsistency and delayed updates. The preceding issues can be resolved by integrating configuration centers with the instances. Configuration information can be dynamically modified, and stored and managed in a centralized manner. This ensures configuration isolation and synchronization between different environments and instances, and improves the flexibility and security of configuration updates.

Prerequisites

  • Maven is downloaded and environment variables are configured.

  • A Spring Cloud application is available. If no Spring Cloud application is available, you can use the demo application provided in this topic: nacos-service-config.zip.

  • A Nacos engine is created. For more information, see Create a Nacos engine.

    Important

    If your application does not reside in the same region as the MSE Nacos configuration center or is not deployed on an Alibaba Cloud instance, you must select Internet as the network type when you create the Nacos engine.

    To ensure that your application can access MSE over the Internet, you must configure a whitelist. For more information, see Configure a public IP address whitelist.

  • A namespace is created. For more information, see Create a namespace.

Overview

image

You must integrate an MSE Nacos configuration center with the Spring Cloud application, publish the useLocalCache=true configuration, and then publish the useLocalCache=false configuration in the MSE Nacos console. Then, request the related configuration interfaces of the application by using the command-line interface (CLI) to obtain the useLocalCache values. You can verify the implementation of the dynamic refresh feature of the MSE Nacos configuration center based on the results of the two requests.

  1. Create and publish a configuration: Create and publish a configuration in the MSE console.

  2. Integrate an MSE Nacos configuration center: Use an MSE Nacos configuration center to manage the Spring Cloud application configurations based on sample code.

  3. Verify the implementation of the dynamic refresh feature: Modify the configurations in the MSE console to use the dynamic refresh feature of the application.

Step 1: Create and publish a configuration

  1. Log on to the MSE console, and select a region in the top navigation bar.

  2. Find the instance that you want to manage and click the name of the instance.

  3. In the left-side navigation pane, choose Configuration Management > Configurations.

  4. In the upper part of the page that appears, select the namespace that you created.

  5. Click Add Configuration. In the Add Configuration panel, configure the parameters, as shown in the following figure.

    Note

    The configurations in the following figure are only for reference. You can configure the parameters based on your business requirements. For more information about the parameters, see Create a configuration.

    image

  1. After you configure the parameters, click Release. The new configuration is displayed on the Configurations page.

Step 2: Integrate an MSE Nacos configuration center

  1. Optional. If no Spring Cloud application is available, use the demo application provided in this topic.

  2. Add the dependency of the MSE Nacos configuration center to the pom.xml file of the Spring Cloud application.

    Note

    The versions of Spring Cloud Alibaba, Spring Cloud, and Spring Boot must be matched. You can visit the Spring Cloud Alibaba official website to view Release Notes, and select the versions that adapt to your application. We recommend that you upgrade the versions to 2023.x.

            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
                <version>2021.0.4.0</version>
            </dependency>
  3. Add Nacos-related configurations to the configuration file of the Spring Cloud application. Sample configurations:

    Important

    If you want to specify a namespace for your application, enter the namespace ID.

    # The address of your Nacos server.
    spring.cloud.nacos.config.server-addr=mse-XXX.nacos-ans.mse.aliyuncs.com:8848
    # Specify the MSE Nacos namespace. If you want to access the default public namespace, set this parameter to null or leave this parameter empty. 
    spring.cloud.nacos.config.namespace=24075300-XXXX-XXXX-XXXX-0c17aa9f744b
    # Import a specific configuration file.
    spring.config.import=nacos:mse-nacos-config-client.properties?group=DEFAULT_GROUP&refreshEnabled=true

    On the Instances page, you can view the public endpoint of the MSE Nacos configuration center. The public endpoint is in the mse.XX.nacos.mse.aliyuncs.com format.

    image

  4. After the preceding operations are complete, run the mvn clean package command to recompile and package the application.

Step 3: Verify the implementation of the dynamic refresh feature

Note

The following verification operations are based on the demo Spring Cloud application and sample configurations provided in this topic. If you use other Spring Cloud applications or custom configurations of the MSE Nacos configuration center, verify the implementation of the dynamic refresh feature by referring to the following steps.

  1. Start the Spring Cloud application and run the main function of the startup class.

  2. Run the following command on the CLI to query useLocalCache of the MSE Nacos configuration center. The useLocalCache=true configuration is returned.

    # Change the IP address and port number of your application.
    curl http://Application IP address:18083/getConfig 
  3. Change the configuration to useLocalCache=false in the MSE console and publish the new configuration.

  4. Run the preceding command again. The useLocalCache=false configuration is returned, which indicates that the application can obtain the latest useLocalCache value from the MSE Nacos configuration center without the need to restart the application.

References