「整合系列」配置隔离(“Consolidation series” configuration isolation)

本篇文章主要内容是将所有的微服务接入Nacos配置中心并按环境进行隔离。

配置中心集成

在SpringCloud Alibaba体系中是使用Nacos作为配置中心,这样Nacos既可以作为注册中心也可以作为配置中心,相当于SpringCloud中的Eureka + Config。要接入Nacos的配置中心也很简单,只需要如下几步:

(1)引入配置中心组件spring-cloud-starter-alibaba-nacos-config

<dependency>
	<groupId>com.alibaba.cloud</groupId>
	<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>

(2)在resource中新建文件bootstrap.yml,配置应用名称和注册中心地址

spring:
  application:
    name: account-service
  cloud:
    nacos:
      config:
        server-addr: 127.0.0.1:8848
        file-extension: yml
        #不特别指定,默认是spring.application.name
        name: account-service

这里指定文件后缀为yml。

(3)在nacos控制台建立配置文件

————————

The main content of this article is to connect all micro services to the Nacos configuration center and isolate them according to the environment.

Configuration center integration

In the spring cloud Alibaba system, Nacos is used as the configuration center, so that Nacos can be used as both the registration center and the configuration center, which is equivalent to Eureka + config in spring cloud. It is also very simple to access the configuration center of Nacos, which only needs the following steps:

(1)引入配置中心组件spring-cloud-starter-alibaba-nacos-config

<dependency>
	<groupId>com.alibaba.cloud</groupId>
	<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>

(2) Create a new file bootstrap. In resource YML, configure application name and registry address

spring:
  application:
    name: account-service
  cloud:
    nacos:
      config:
        server-addr: 127.0.0.1:8848
        file-extension: yml
        #不特别指定,默认是spring.application.name
        name: account-service

The file suffix specified here is YML.

(3) Creating a configuration file in the Nacos console