Nacos Config User-defined Namespace and Group creation

Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Namespace
  • Under the Command Space menu of the Nacos console, create a namespace
  • Add the following configuration to bootstrap.yml
spring:
	cloud:
	  nacos:
	  	config:
	  		Namespace: XXX (ID of the command space in the namespace)
Copy the code
Group

The Group does not need to be created in advance. You only need to specify the Group when creating the Group.

  • Specify the Group to which the configuration belongs on the New Configuration page of the Nacos console
  • Add the following configuration in bootstrap.yml
spring:
	cloud: 
		nacos:
			config:
				group: DEV_GROUP
Copy the code
Data ID

The Data ID is the ID of a configuration set in Nacos and is used to divide the configuration set of the system. The configuration can be divided by the name of the configuration file or by the full path of the Java package, depending on the dimension of the Data ID.

Spring Cloud Alibaba Nacos Config supports automatic configuration with Data ID

spring.cloud.nacos.config.ext-config[0].data-id=server1.properties
spring.cloud.nacos.config.ext-config[0].group=DEFAULT_GROUP
spring.cloud.nacos.config.ext-config[0].refresh=true
Copy the code

Related Parameters

  • Spring. Cloud. Nacos. Config. Ext – config [n] : support multiple Data ID extension configuration, consists of three attributes: Data ID, group and refresh
  • Spring. Cloud. Nacos. Config. Ext – config [n]. The data – id: specify nacos config data id
  • Spring. Cloud. Nacos. Config. Ext – config [n]. Group: specifies the Data group ID’s
  • Spring. Cloud. Nacos. Config. Ext – config [n]. Refresh: control Data ID in the configuration change whether situational awareness of the latest configuration value is needed. The default is false and dynamic refresh is not implemented.

Note:

  • Spring. Cloud. Nacos. Config. Ext – config [n]. Data – id values must take the file extensions, such as the properties, yaml, etc.
  • Spring. Cloud. Nacos. Config. Ext – config [n]. Data – id configure multiple data id, the greater the value of n, the higher the priority

You can customize the extended Data ID configuration to solve the configuration sharing problem of multiple applications. If an application has multiple configuration files, pay attention to ext-config and Spring.. application.name.{spring.. application.name}.spring.. Application. Name.{file-extension:properties} has a higher priority.