1.pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-nacos-config</artifactId>
<version>0.9.0.RELEASE</version>
</dependency>
2.在nacos 管理中心 的配置列表 添加配置
3.在服务提供者 创建controller
package com.sunup.practice.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RefreshScope
public class ConfigController {
@Value("${username:lime}")
private String username;
@GetMapping("/username")
public String get(){
return username;
}
}
4.重启服务提供者
访问http://localhost:8761/username