1,下载Nacos,并放到服务器

image.png

2,进度到Nacos所在目录并解压

image.png

3,进入到nacos目录并启动

image.png
image.png

http://192.168.xxx.xxx:8848/nacos/index.html
默认登陆账号和密码
账号:nacos
密码:nacos

4,进入项目配置信息

(此处为spring-boot项目,文档和代码示例可以再次看:
https://nacos.io/zh-cn/docs/q...)
image.png

5,测试可以正常使用:


@RestController
@NacosPropertySource(dataId = "test",autoRefreshed = true)
public class test1 {

    @NacosValue(value = "${url:kason}", autoRefreshed = true)
    private String url = "";

    @NacosValue(value = "${user:kason}", autoRefreshed = true)
    private String user = "";

    @NacosValue(value = "${pass:pass}", autoRefreshed = true)
    private String pass = "";

    @GetMapping(value="/testNacos")
    public Map<String,String> testNacos() {
        Map<String, String> map = new HashMap<>();
        map.put("url", url);
        map.put("user", user);
        map.put("pass", pass);
        return map;
    }

    @GetMapping(value="/test01")
    public String test01() {
        return "how are you?";
    }
    
}

image.png
image.png


Kason
209 声望6 粉丝