When Nacos serves as the service configuration center, the server is the web version, and the configuration is newly created. The client, that is, the application, introduces dependencies and adds related configurations.

Before starting again, I will share an experience of not using the configuration center.

The company arranged for me to be responsible for a hospital's unified payment platform project. At first, I thought about it simple. If you don’t have a configuration center, you need to maintain it, which is troublesome. But in fact, if you want to modify the configuration, you need to modify the configuration file, then package, upload the jar (because it is an intranet), and then the operation and maintenance colleagues are responsible for the deployment. Every time you need to change a configuration, you need to go through the above process completely. One day, I couldn't stand it anymore, so I got the Nacos configuration center. If you need to change the configuration again, you only need to change the configuration center, and then restart the service.

Nacos configuration center is divided into server and client.

The following is divided into server and client, respectively, to demonstrate in detail.

1 server

1.1 New configuration

1.2 Configuration list

1.3 Configuration details

2 Client

2.1 Dependence

<!-- nacos 服务配置 -->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>

2.2 Automatic configuration

package com.fengwenyi.demouserservicecore.config;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;

/**
 * @author <a href="https://www.fengwenyi.com">Erwin Feng</a>
 */
@EnableAutoConfiguration
@Configuration
public class AutoConfigConfiguration {
}

2.3 Configuration

spring.application.name=demo-user-service-core
spring.profiles.active=dev

spring.cloud.nacos.config.server-addr=127.0.0.1:8848
spring.cloud.nacos.config.file-extension=yaml
spring.cloud.nacos.config.group=springcloud-alibaba-demo

The specified configuration file name is demo-user-service-core-dev.ymal .

data


冯文议
183 声望20 粉丝

软件开发工程师,专注于程序设计与开发。