1.pom集成依赖jar
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>1.4.1</version>
</dependency>
2.resources下新建bootstrap.properties
#nacos地址
spring.cloud.nacos.config.server-addr=http://121.19.25.299:8848
spring.cloud.nacos.config.username=nacos
spring.cloud.nacos.config.password=nacos
spring.application.name=springboot-demo
spring.profiles.active=dev
spring.cloud.nacos.config.file-extension=yaml
spring.cloud.nacos.config.namespace=${spring.profiles.active}
3.nacos上配置命名空间
备注: bootstrap中的config.namespace的value对应nacos命名空间ID
4.在nacos上新建yaml文件
备注:
data id 下的配置文件名称:spring.application.name + "-" + spring.profiles.active + "yaml".