什么是配置中心?
相关产品:
Nacos 配置中心面板介绍
项目依赖
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency>
配置文件优先级讲解
配置实操
spring:
application:
name: xdclass-order-service
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848 #Nacos配置中心地址
file-extension: yaml #文件拓展格式
profiles:
active: dev
启动微服务服务验证
浏览器访问 http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=xdclass-order-service-dev.yaml&group=DEFAULT_GROUP ? 如果出现 config dta not exist 建议重启nacos
重新构建下项目
?
mvn clean package -U
?
然后重启IDEA
dataId 组成,在 Nacos Spring Cloud 中,dataId 的完整格式如下
${prefix}-${spring.profiles.active}.${file-extension}
?
prefix 默认为 spring.application.name 的值
?
spring.profiles.active 即为当前环境对应的 profile
当 spring.profiles.active 为空时,对应的连接符 - 也将不存在,dataId 的拼接格式变成 ${prefix}.${file-extension}
?
file-exetension 为配置内容的数据格式,可以通过配置项 spring.cloud.nacos.config.file-extension 来配置。目前只支持 properties 和 yaml 类型。
什么是动态刷新配置?
配置实战
@RefreshScope public class OrderController { @Value("${video.title}") private String videoTitle; }
AlibabaCloud 核?组件配置中心 Nacos 实战
原文:https://www.cnblogs.com/jwen1994/p/13970002.html