pom.xml 引用
<!-- Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
连接并获取nacos的配置
ConfigService nacosService = nacosConfigManager.getConfigService();
String heartbeatYml = nacosService.getConfig("heartbeat.yaml","DEFAULT_GROUP",1000);
读取数据,将yaml转成map
Map<String,Map<String,String>> obj = toObject(heartbeatYml,Map.class);
currentServerIp = obj.get("server").get("ip");
网友评论