7creation and use of Nacos online configuration file

Posted by broann on Fri, 04 Mar 2022 21:25:58 +0100

Creation and use of Nacos online configuration file

(key) offline configuration files can be used for configuration management in the development stage. When the service is online, all local configurations can be added to Nacos configuration management for online configuration management.

1.Nacos client settings

1.1 launch and open the Nacos client page
1.2 create a new namespace

As follows:

Namespace name: dev
 Description: development phase
1.3 switch to configuration management - configuration list, select a new namespace (e.g. dev), and create an online configuration file;
New configuration
	Data ID:datasource.properties
	Description: data source
	Configuration format: Properties
	Configuration content:
1.4 add all local configuration files (application.yml, application.properties, etc.) under the current microservice to the online configuration management of Nacos, and use the above methods to add them one by one.
Data Id							Group

datasource.properties			  dev

mybatis.yml						 dev

other.yml						 dev

qilemo-product.properties		   dev

2.Java configuration center configuration item (bootstrap.properties)

2.1 configuration center namespace: (if it is not set, all configuration files will be found under the public namespace by default. If it cannot be found, it will be found from the local configuration file application.yml)
2.2 configuration center configuration Group: (if it is not set, it will be found from the DEFAULT_GROUP group by default. If it cannot be found, it will be found from the local configuration file application.yml)
2.3 configuration center configuration file name (Data ID): (if it is not set, the micro service name or the configuration in the micro service name. Properties will be used by default. If it cannot be found, it will be found from the local configuration file application.properties)

The first three items are fully configured as follows:

2.4 if there are multiple configuration files (for example: datasource.properties, mybatis.yml, other.yml, qilemo-product.properties), use the following command to add them;

The above complete configuration contents are as follows: (the namespace namespace is a global configuration, and the locations of all the following configuration files are found under this namespace. If it is not set, it is found under the public public namespace by default)


3. Start the microservice for testing. Before testing, please comment out the configuration information that the local configuration file (application.yml) has been configured online

3.1 the configuration files added above are: datasource properties,mybatis.yml,other.yml,qilemo-product.properties; Apply Just comment out all the contents in the YML configuration file.
#spring:#  datasource:#    username: root#    password: 123456789#    url: jdbc:mysql://    driver-class-name: com.mysql.jdbc.Driver#  cloud:#    nacos:#      discovery:#        server-addr: localhost:8848#  application:#    name: qilemo-product##mybatis-plus:#  mapper-locations: classpath*:/mapper/**/*.xml#  global-config:#    db-config:#      id-type: auto##server:#  port: 20001

4. View endpoint information (please see the following article for details)

If the service can still be started normally without exception when the local data source is unavailable, it indicates that the online configuration has taken effect. At this time, you can check whether the online configuration has been called through the Endpoint. For details, please check:

4.8 Nacos configuration management- Endpoint Information viewing.md

Topics: Java Operation & Maintenance Back-end Spring Cloud