Procházet zdrojové kódy

增加OkHttp配置文件读取

tags/v1.0.0^2
林万龙 před 3 roky
rodič
revize
928efde493
2 změnil soubory, kde provedl 24 přidání a 3 odebrání
  1. +2
    -2
      src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java
  2. +22
    -1
      src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java

+ 2
- 2
src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java Zobrazit soubor

@@ -15,12 +15,12 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@Slf4j
public class DipperPositionController {
@Value(value = "${position.hello}")
@Value(value = "${position-server.serverAddr}")
private String hello;
//RzlAccount rzlAccount;

@RequestMapping("/getPos")
public String getPos() {
return "return position = " + hello;
return "return serverAddr = " + hello;
}
}

+ 22
- 1
src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java Zobrazit soubor

@@ -19,9 +19,13 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.YamlMapFactoryBean;
import org.yaml.snakeyaml.Yaml;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Properties;


@@ -34,7 +38,7 @@ import java.util.Properties;
@Slf4j
public class DipperPositionServer {

@Autowired PositionConfigInfo positionConfigInfo;
// @Autowired PositionConfigInfo positionConfigInfo;
private String serverAddr="172.16.192.26";
private String timeAsycServerPort="9011";
private String posAsycServerPort="9013";
@@ -42,6 +46,23 @@ public class DipperPositionServer {

public DipperPositionServer() throws NacosException {
//String serverAddr = positionConfigInfo.getServerAddr();
try {
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);

ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(content.getBytes());
Yaml yaml = new Yaml();
Map m1 = (Map) yaml.load(tInputStringStream);
Map m2 = (Map) m1.get("position-server");
log.info("Map server is:" + m2.get("serverAddr"));
} catch (Exception ex) {
ex.printStackTrace();
}
log.info("Config serverAddr is " + serverAddr);
}
/*


Načítá se…
Zrušit
Uložit