Shared and Extended Configuration Support in Nacos
In multi-module microservice architectures, common infrastructure settings—such as database connection strings, Redis endpoints, message broker URIs, or observability parameters—are frequently reused across services. To avoid duplication and simplify maintenance, Nacos Config provides two mechanisms for loading external configuration sources: shared-configs and extension-configs.
Both accept a list of configuration entries, each supporting the following fields:
data-id: The identifier of the configuration item (e.g.,database.yaml).group: Optional namespace grouping; defaults toDEFAULT_GROUPif omitted.refresh: Enables dynamic reloading when the remote config changes; defaults totrue.
Configuration Example
spring:
application:
name: order-service
cloud:
nacos:
config:
server-addr: nacos.example.com:8848
namespace: 7a3b1f9c-2d4e-4567-a8c1-0e2f3d4b5a67
shared-configs:
- data-id: base-logging.yaml
group: COMMON_CONFIG_GROUP
- data-id: cache-redis.yaml
group: COMMON_CONFIG_GROUP
extension-configs:
- data-id: order-db-overrides.yaml
group: ORDER_SERVICE_GROUP
refresh: true
- data-id: feature-toggles.yaml
group: ORDER_SERVICE_GROUP
refresh: false
Note: File extensions like
.yamlmust be explicitly included indata-id. Do not setfile-extensionseparately—the parser infers format from the suffix.
Functional Distinction Between shared-configs and extension-configs
While both support identical syntax and runtime behavior, their semantic roles differ based on deployment context and override semantics:
-
shared-configsis intended for cross-service configuration reuse. These entries typical reside in a generic group (e.g.,DEFAULT_GROUP) and apply uniformly unless overridden. -
extension-configsserves scoped customization—e.g., per-application tweaks to shared values. For instance, most services may use a standard JDBC URL fromshared-configs, while one service (inventory-service) overrides just thespring.datasource.urlvia its ownextension-configsentry under its dedicatedINVENTORY_GROUP.
Loading Order and Precedence Rules
Configuration resolution follows strict precedence:
-
Within the same category, later-listed items supersede earlier ones:
extension-configs[2]>extension-configs[1]>extension-configs[0]shared-configs[1]>shared-configs[0]
-
Across categories, priority descends as:
- Application-specific main configuration (derived from
spring.application.name) extension-configsshared-configs
- Application-specific main configuration (derived from
This hierarchy ensures that environment- or service-level adjustments take precedence over broad defaults without requiring conditional logic in code.