Procházet zdrojové kódy

增加配置文件读取

tags/v1.0.0^2
林万龙 před 3 roky
rodič
revize
558005fd9a
2 změnil soubory, kde provedl 20 přidání a 12 odebrání
  1. +2
    -0
      src/main/java/com/telpo/dipperposition/co/RzlAccount.java
  2. +18
    -12
      src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java

+ 2
- 0
src/main/java/com/telpo/dipperposition/co/RzlAccount.java Zobrazit soubor

@@ -3,6 +3,7 @@ package com.telpo.dipperposition.co;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.stereotype.Component;

/**
* @program: RzlAccount
@@ -13,6 +14,7 @@ import lombok.ToString;
@Getter
@Setter
@ToString
@Component
public class RzlAccount {

private String hello;


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

@@ -3,7 +3,9 @@ package com.telpo.dipperposition.controller;
import com.alibaba.cloud.nacos.parser.NacosDataParserHandler;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException;
import com.telpo.dipperposition.co.RzlAccount;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@@ -25,20 +27,24 @@ import com.alibaba.nacos.api.config.listener.Listener;
@Slf4j
public class DipperPositionController {

@Autowired RzlAccount rzlAccount;

@RequestMapping("/getPos")
public String getPos() throws NacosException, InterruptedException, IOException {
String group = "DEFAULT_GROUP";
String dataId = "dipperposition-service";
String positionId = "position.hello";
Properties properties = new Properties();
String serverAddr = "172.16.192.26";
properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
ConfigService configService = NacosFactory.createConfigService(properties);
String content = configService.getConfig(dataId, group, 10000);
System.out.println(content);
//log.info(positionId + ":" + content.positionId)
Map<String, Object> dataMap = NacosDataParserHandler.getInstance().parseNacosData(content,"yaml");
return dataMap == null ? "" : (String)dataMap.get(positionId);
// String group = "DEFAULT_GROUP";
// String dataId = "dipperposition-service";
// String positionId = "position.hello";
// Properties properties = new Properties();
// String serverAddr = "172.16.192.26";
// properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
// ConfigService configService = NacosFactory.createConfigService(properties);
// String content = configService.getConfig(dataId, group, 10000);
// System.out.println(content);
// //log.info(positionId + ":" + content.positionId)
// Map<String, Object> dataMap = NacosDataParserHandler.getInstance().parseNacosData(content,"yaml");
// return dataMap == null ? "" : (String)dataMap.get(positionId);

return rzlAccount.getHello();
//return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString();
}
}

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