基本环境: 1. 根据手册,本地搭建一个nacos server, 版本 2.2.3, standalone 2. 利用apisix,给nacos server加一层网关代理 { "uri": "/nacos/*", "name": "local.8848", "upstream_id": "xx", "enable_websocket": true, "status": 1 } { "nodes": [ { "host": "host.docker.internal", "port": 8848, "weight": 100 } ], "type": "roundrobin", "pass_host": "pass", "name": "local.nacos" } 访问: `http://localhost:9080/nacos/index.html` 都很正常的,也可以用 curl -X GET "http://localhost:9080/nacos/v1/cs/configs?dataId=nacos.cfg.dataId" 配置了值: namespace=public dataId=nacos.cfg.dataId group=DEFAULT_GROUP value: // properties time.pattern=yyyy-mm-dd 目前问题是: 1. 用spring boot读取不到配置 spring boot里的配置就非常简单, nacos.config.server-addr=http://localhost:9080 spring boot代码: // 版本 0.2.12 @SpringBootApplication @NacosPropertySource(dataId = "nacos.cfg.dataId", type = ConfigType.PROPERTIES, autoRefreshed = true) public class NacosConfigApplication { public static void main(String[] args) { SpringApplication.run(NacosConfigApplication.class, args); } } @Controller public class ConfigController { @NacosValue(value = "${time.pattern}", autoRefreshed = true) private String value; @RequestMapping(value = "/config/get", method = GET) @ResponseBody public String get() { return value; } } 直接用sdk也不行 com.alibaba.nacos nacos-client 2.3.0 // 2.2.3, 2.2.4都试过 public static void main(String[] args) throws Exception { String serverAddr = "http://localhost:9080"; 就可以了 String dataId = "nacos.cfg.dataId"; String group = "DEFAULT_GROUP"; Properties properties = new Properties(); properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr); ConfigService configService = NacosFactory.createConfigService(properties); String content = configService.getConfig(dataId, group, 5000); // 换成 serverAddr=http://localhost:8848, content就是配置的值了 System.out.println(content); // content=null, }