Ignore the empty nacos configuration and get it based on dataId[terminal-common.yaml] & group[DEFAULT_GROUP]
时间: 2023-08-15 12:14:19 浏览: 128
To retrieve the configuration based on dataId "terminal-common.yaml" and group "DEFAULT_GROUP" in Nacos, you can use the Nacos Java SDK. Here's some sample code that demonstrates how to do this:
```java
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
public class NacosConfigDemo {
public static void main(String[] args) throws Exception {
String serverAddr = "localhost:8848"; // Nacos server address
String dataId = "terminal-common.yaml"; // configuration dataId
String group = "DEFAULT_GROUP"; // configuration group
ConfigService configService = NacosFactory.createConfigService(serverAddr);
String config = configService.getConfig(dataId, group, 5000); // timeout set to 5 seconds
System.out.println(config); // print out the configuration content
}
}
```
Make sure to add the Nacos Java SDK dependency to your project's build file.
阅读全文