In Nacos, the spring.cloud.nacos.config.shared-configs
property is used to load additional shared configurations that are not directly tied to the specific application but can be shared across multiple applications or environments. These shared configurations can be stored in Nacos and pulled into multiple Spring Boot applications.
When using spring.cloud.nacos.config.shared-configs
, the data-id
refers to the identifier of the configuration file in Nacos, which can be a .properties
or .yml
file, or any other configuration format supported by Nacos.
How spring.cloud.nacos.config.shared-configs[0].data-id
works
The spring.cloud.nacos.config.shared-configs
array allows you to specify multiple shared configurations that your application can load from Nacos.
Here’s an example of how to use shared-configs
in the application.properties
or application.yml
of your Spring Boot application.
Example 1: Using spring.cloud.nacos.config.shared-configs
in application.properties
In this example, you want to load a shared configuration (shared-config.properties
) from Nacos, which can be used across multiple services.
# application.properties spring.application.name=my-app spring.cloud.nacos.config.server-addr=localhost:8848 # Nacos