public JSONObject getConfig(){
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR,"nocas地址");
properties.put(PropertyKeyConst.NAMESPACE,"工作空间名");
//账号密码
//properties.put(PropertyKeyConst.USERNAME,"账号");
//properties.put(PropertyKeyConst.PASSWORD."密码);
//这里最好改成单例bean,来生成configService
ConfigService configService = NacosFactory.createConfigService(properties);
//文件是json
String content = configService.getConfig("文件名","分组",3000L);
//文件是propertites
//Properties contentProperties = new Propertites();
//contentProperties.load(new StringReader(content));
//return new JSONObject(contentProperties);
//销毁nacos线程
//configService.shutDown();
return JSONObject.parseObject(content);
}
获取nacos配置文件的内容
于 2023-05-09 15:10:51 首次发布