Cloud Native 7 min read

How to Load Multiple Nacos Configurations and Share Them in Spring Cloud

This article explains how to split Spring Cloud application settings into separate Nacos configuration files, load them together using ext-config and shared-dataids properties, control refresh behavior, and understand the priority order when overlapping keys appear, providing practical code examples and reference links.

Programmer DD
Programmer DD
Programmer DD
How to Load Multiple Nacos Configurations and Share Them in Spring Cloud

In previous articles we introduced how to create configuration content in Nacos, the mapping between Nacos configuration and Spring application configuration, and multi‑environment configuration management.

When an application needs to split configuration into multiple files (e.g., actuator.properties and log.properties) for sharing, Nacos can load them together. The loading is controlled by three parameters: spring.cloud.nacos.config.prefix, spring.cloud.nacos.config.file-extension, and spring.cloud.nacos.config.group.

Loading multiple configurations

By default Spring Cloud loads the configuration whose data‑id is ${spring.application.name}.properties in the DEFAULT_GROUP.

To load additional files we create two Data‑ID entries in Nacos ( actuator.properties and log.properties) with the same group, then configure the ext-config property in the Spring application:

spring.cloud.nacos.config.ext-config[0].data-id=actuator.properties
spring.cloud.nacos.config.ext-config[0].group=DEFAULT_GROUP
spring.cloud.nacos.config.ext-config[0].refresh=true

spring.cloud.nacos.config.ext-config[1].data-id=log.properties
spring.cloud.nacos.config.ext-config[1].group=DEFAULT_GROUP
spring.cloud.nacos.config.ext-config[1].refresh=true

The ext-config list is an array; each element contains data-id, group and refresh. The refresh flag enables automatic refresh for the extra configuration.

Shared configuration

Nacos also provides a shortcut to load several shared configurations at once:

spring.cloud.nacos.config.shared-dataids=actuator.properties,log.properties
spring.cloud.nacos.config.refreshable-dataids=actuator.properties,log.properties

When the same key exists in multiple configurations, the loading order is A < B < C, where A is shared‑dataids, B is ext‑config, and C is the default configuration.

Reference

Nacos official documentation

Code example

The full example can be found in the repository:

GitHub: https://github.com/dyc87112/SpringCloud-Learning/

Gitee: https://gitee.com/didispace/SpringCloud-Learning/

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaSpring CloudShared Config
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.