1.添加依赖config
<!-- nacos配置中心-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- 引入bootstrap依赖用来使bootstrap配置有效-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.0.2</version>
</dependency>
2.创建bootstrap.properties文件
//添加微服务模块名
spring.application.name=gulimall-coupon
//添加nacos服务地址
spring.cloud.nacos.server-addr=127.0.0.1:8848
启动nacos服务器 windows可以在bin目录下点击startup.cmd启动服务
可能会出错 可以在bin目录下打开cmd 使用单机命令启动服务
sh startup.sh -m standalone 默认是集群的方式启动
3.给配置中心默认添加 当前应用名.properties
动态的获取配置 使用两个注解
@RefreshScope 在xxxcontroller添加 动态过去并刷新配置
@Value("${coupon.user.name}") 引入配置文件属性
0575-88307756
默认优先使用配置中心的