瀏覽代碼

增加配置文件读取

tags/v1.0.0^2
林万龙 3 年之前
父節點
當前提交
a3b512535d
共有 1 個檔案被更改,包括 23 行新增1 行删除
  1. +23
    -1
      src/main/java/com/telpo/dipperposition/DipperPositionApplication.java

+ 23
- 1
src/main/java/com/telpo/dipperposition/DipperPositionApplication.java 查看文件

@@ -1,5 +1,10 @@
package com.telpo.dipperposition;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException;
import com.telpo.dipperposition.server.DipperPositionServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
@@ -8,7 +13,8 @@ import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

import java.net.InetSocketAddress;
import java.util.Properties;
import java.util.concurrent.Executor;

/**
* @program: gateway
@@ -27,10 +33,26 @@ public class DipperPositionApplication {
log.info("北斗定位服务开始!");
SpringApplication.run(DipperPositionApplication.class, args);
log.info("北斗定位服务启动!");
try {
test();
} catch (Exception e) {
log.error(e.getMessage());
}
//启动服务端
DipperPositionServer nettyServer = new DipperPositionServer();
nettyServer.startTimeAsnc();
nettyServer.startPosAsnc();
nettyServer.startStarsAsnc();
}

private static void test() throws NacosException {
String serverAddr = "172.16.192.26";
String dataId = "dipperposition-service";
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);
System.out.println(content);
}
}

Loading…
取消
儲存