前言
通过前两篇文章:
相信大家已经对nacos作为注册中心的基本使用已经有了一定的了解。
然而,nacos远远不止于此,本文我们来看一下nacos作为配置中心在springcloud中的使用
我的环境
windows10
jdk8
springcloud:finchley.release
springboot:2.0.4.release
spring-cloud-alibaba-dependencies:0.2.2.release
nacos-server:1.0.1
本文的项目demo继续沿用之前文章中的聚合工程nacos,若小伙伴还没有之前的环境,可至源码地址中下载
启动nacos-server
进入bin文件夹(目录:nacos-server-1.0.1\nacos\bin),直接双击执行startup.cmd文件,这里具体的启动细节就不再说明
新建配置
在nacos-server中新建配置,其中data id它的定义规则是:${prefix}-${spring.profile.active}.${file-extension}
prefix 默认为 spring.application.name 的值,也可以通过配置项 spring.cloud.nacos.config.prefix 来配置。
spring.profile.active 即为当前环境对应的 profile,可以通过配置项 spring.profile.active 来配置。
file-exetension 为配置内容的数据格式,可以通过配置项 spring.cloud.nacos.c