github官网地址:
1、Nacos作为配置中心
2、Nacos作为服务注册/发现
1)、引入依赖,
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
2)、创建一个bootstrap.properties
spring.application.name=nacos-config-example
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
3)、需要给配置中心默认添加一个叫 数据集(Data Id) mall-coupon.properties.默认规则 :应用名.properties
4、给应用名.properties 添加任何配置
5、动态获取配置
@RefreshScope
@RestController
@RequestMapping("coupon/coupon")
public class CouponController {
@Autowired
private CouponService couponService;
@Value("${coupon.user.name}")
private String name;
@Value("${coupon.user.age}")
private Integer age;
如果配置中心和当前应用配置文件都配置了相同的项,优先使用中心的配置。