SpringCloud配置nacos为配置中心


先在pom中引入包

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

然后在 bootstrap.properties 中配置

##是否开启nacos配置中心
spring.cloud.nacos.config.enabled=true
## Nacos 配置中心
spring.cloud.nacos.config.server-addr=${middleware.nacos.host}
spring.cloud.nacos.config.namespace=standard
spring.cloud.nacos.config.prefix=${spring.application.name}
spring.cloud.nacos.config.file-extension=properties
spring.cloud.nacos.config.group=DEFAULT_GROUP

然后启动服务,看到日志中输出 dataId= 字样就说明服务起多个了

[n] [a] [|] 2024-10-23 00:20:33.423 [ INFO] 77152 [      main] c.a.c.n.r.NacosContextRefresher               : [Nacos Config] Listening config: dataId=vxlink-common.properties, group=DEFAULT_GROUP
[n] [a] [|] 2024-10-23 00:20:33.426 [ INFO] 77152 [      main] c.a.c.n.r.NacosContextRefresher               : [Nacos Config] Listening config: dataId=vxlink-common-local-auto.properties, group=DEFAULT_GROUP
[n] [a] [|] 2024-10-23 00:20:33.426 [ INFO] 77152 [      main] c.a.c.n.r.NacosContextRefresher               : [Nacos Config] Listening config: dataId=vxlink-common-fast.properties, group=DEFAULT_GROUP
[n] [a] [|] 2024-10-23 00:20:33.426 [ INFO] 77152 [      main] c.a.c.n.r.NacosContextRefresher               : [Nacos Config] Listening config: dataId=vxlink-common-local.properties, group=DEFAULT_GROUP
[n] [a] [|] 2024-10-23 00:20:33.426 [ INFO] 77152 [      main] c.a.c.n.r.NacosContextRefresher               : [Nacos Config] Listening config: dataId=vxlink-common-common-auto.properties, group=DEFAULT_GROUP
[n] [a] [|] 2024-10-23 00:20:33.427 [ INFO] 77152 [      main] c.a.c.n.r.NacosContextRefresher               : [Nacos Config] Listening config: dataId=vxlink-common-common.properties, group=DEFAULT_GROUP
[n] [a] [|] 2024-10-23 00:20:33.427 [ INFO] 77152 [      main] c.a.c.n.r.NacosContextRefresher               : [Nacos Config] Listening config: dataId=vxlink-common, group=DEFAULT_GROUP

评论