This is the 17th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

Antecedents to review

In our last article, we described how the SpringCloud project has taken its first steps towards learning about microservices by integrating Nacos service registry.

In previous articles, we have covered only the basic integration of these components for the time being, but don’t let me mislead you, these are just basic uses, not the same as the real world, so there is a lot to consider when using these components in a real project.

We’ll talk about that when we get a chance.

SpringCloud integrates Nacos configuration management capabilities

The configuration management function of microservices is realized by SpringCloud Config component, while SpringCloud Alibaba series is realized by Nacos.

In this case, Nacos in addition to service governance functions, but also to achieve configuration management functions, the power of the function will not say, with the release of Nacos2, the integration of various functions has been realized, here if you are interested, you can go to the official website to see the version update log.

Integrate in the old project from the previous article

Let’s make a copy of the project from the previous article and open it using IDEA.

Introduce jar packages related to Nacos configuration management

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
Copy the code

Configure parameters related to Nacos configuration management

Modify the application.yml file

Spring: application: name: demo-config cloud: nacos: discovery: server-addr: 127.0.0.1:8848 config: server-addr: 127.0.0.1:8848 file-extension: yaml group: DEFAULT_GROUP prefix: ${spring.application.name}Copy the code

Add config configuration,

Server-addr: indicates the IP address of the nacos server

File-extension: Specifies the file type

Group: configures a group

Prefix: the prefix of the file name. If you configure different environments, you only need to configure the prefix. Nacos will add different suffixes based on your environment.

Add the configuration on the Nacos page

We open the NacOS server page and enter the menu as shown below.

We usually add configuration to this feature.

I’ve entered some parameters here, and when we run the project, it will load our local configuration first, then load the configuration here, and if it’s the same, it will be overwritten.

Extra knowledge

It is important to note that we usually use the Application configuration file, but SpringCloud has an additional configuration file, the Bootstrap configuration file.

It should be mentioned that the Bootstrap configuration file takes precedence over the application configuration file. Therefore, some basic configurations will be performed in the Bootstrap file during normal development. The rest of the configuration is maintained using application profiles, or some configuration information is managed using the NACOS configuration Manager.

conclusion

Nacos configuration center is now mature, there are a few points that we haven’t covered, that is, configuration grayscale publishing and other functions, we will learn about this later.