All Products
Search
Document Center

Microservices Engine:Integrate MSE Nacos as a configuration center

Last Updated:Jun 21, 2026

This topic describes how to integrate an MSE Nacos configuration center with your Spring Cloud application for centralized configuration management and dynamic refresh.

Background information

In a microservices architecture, managing configurations with hard-coded values or static files is difficult, especially as the number of microservices and environments grows. This practice often leads to inconsistent configurations and delayed updates. A configuration center solves these problems by providing a central place to store, manage, and dynamically update configuration data. This ensures configuration isolation and synchronization between different environments and instances, while improving the flexibility and security of configuration updates.

Prerequisites

  • Download Maven and set up the required environment variables.

  • An existing Spring Cloud application. If you do not have one, you can use the demo application provided in this topic: nacos-service-config.zip.

  • Create a Nacos engine.

    Important

    If your application is not in the same region as MSE Nacos or is not on an Alibaba Cloud server, you must select the public network when you create the Nacos engine.

    To ensure your application can access MSE over the public network, you must configure a whitelist. For more information, see Set a whitelist.

  • Create a namespace.

Overview

image

By integrating an MSE Nacos configuration center with a Spring Cloud application, you can experience its dynamic refresh feature by publishing the configuration parameter useLocalCache=true, updating it to useLocalCache=false in the MSE Nacos console, and then requesting the application's configuration API from the command line to retrieve the useLocalCache value and observe the changes.

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

  2. Integrate MSE Nacos: Add the required dependencies and properties to connect your Spring Cloud application to the MSE Nacos configuration center.

  3. Verify dynamic refresh: Modify the configuration in the console and confirm that the application applies the change without a restart.

Step 1: Create and publish configuration

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

  2. Click the name of the target instance.

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

  4. Above the configuration list, select the namespace that you created.

  5. Click Add Configuration. In the Add Configuration panel, enter the following information:

    Note

    This topic provides only a sample configuration for reference. You can create configurations based on your business requirements. For more information about the parameters, see Create a configuration.

    Set Data ID to mse-nacos-config-client.properties and Group to DEFAULT_GROUP. For Configuration Format, select Properties. In the Configuration Content field, enter useLocalCache=true, and then click Publish.

  1. Once you have entered the configuration details, click Publish. The new configuration will appear in the Configurations list.

Step 2: Integrate MSE Nacos

  1. (Optional) If you have not built a Spring Cloud application, you can use this example to quickly set up a simple application.

  2. Add the dependency for the Nacos configuration center to your Spring Cloud application's pom.xml file:

    Note

    The versions of Spring Cloud Alibaba, Spring Cloud, and SpringBoot must be compatible. Check the version release notes on the official Spring Cloud Alibaba website to select a compatible version for your application. Upgrading to the latest 2023.x version is recommended.

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

    Important

    To use a specific namespace in your application, provide its ID.

    # The public endpoint of your Nacos server.
    spring.cloud.nacos.config.server-addr=mse-XXX.nacos-ans.mse.aliyuncs.com:8848
    # Specify the MSE Nacos namespace. To access the default public namespace, leave this blank or do not configure this item.
    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 find the public endpoint of MSE Nacos. The format is mse.XX.nacos.mse.aliyuncs.com.

  4. After you make the changes, run the mvn clean package command to recompile and package the application.

Step 3: Verify dynamic refresh

Note

The following verification steps are based on the sample Spring Cloud application and configuration provided in this topic. If you are using your own application or custom configurations, you may need to adapt these steps.

  1. Start the Spring Cloud application by running the main function in the startup class.

  2. In your terminal, run the following command to get the useLocalCache configuration from the MSE Nacos configuration center. The response is true.

    # Replace with your service's IP address and port.
    curl http://<your-service-ip>:18083/getConfig
  3. In the console, edit the configuration, change its content to useLocalCache=false, and publish it again.

  4. Run the command again. The response is now false. This confirms that the application retrieved the latest useLocalCache data from MSE Nacos without a restart.

Related documents