Browse Source

增加OkHttp配置文件读取

tags/v1.0.0^2
林万龙 3 years ago
parent
commit
928efde493
2 changed files with 24 additions and 3 deletions
  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 View File

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


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

+ 22
- 1
src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java View File

@@ -19,9 +19,13 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.YamlMapFactoryBean; 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.io.InputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Properties; import java.util.Properties;




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


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


public DipperPositionServer() throws NacosException { public DipperPositionServer() throws NacosException {
//String serverAddr = positionConfigInfo.getServerAddr(); //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); log.info("Config serverAddr is " + serverAddr);
} }
/* /*


Loading…
Cancel
Save