Kaynağa Gözat

增加配置文件读取

tags/v1.0.0^2
林万龙 4 yıl önce
ebeveyn
işleme
3c2cfdc8c0
2 değiştirilmiş dosya ile 7 ekleme ve 6 silme
  1. +2
    -2
      src/main/java/com/telpo/dipperposition/config/PositionConfig.java
  2. +5
    -4
      src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java

+ 2
- 2
src/main/java/com/telpo/dipperposition/config/PositionConfig.java Dosyayı Görüntüle

@@ -40,8 +40,8 @@ public class PositionConfig {

PositionConfig()
{
hello = configurableApplicationContext.getEnvironment().getProperty("position.hello");
name = configurableApplicationContext.getEnvironment().getProperty("spring.application.name");
//hello = configurableApplicationContext.getEnvironment().getProperty("position.hello");
//name = configurableApplicationContext.getEnvironment().getProperty("spring.application.name");
}

private static PositionConfig instance;


+ 5
- 4
src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java Dosyayı Görüntüle

@@ -7,6 +7,7 @@ import com.telpo.dipperposition.co.RzlAccount;
import com.telpo.dipperposition.config.PositionConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@@ -27,8 +28,9 @@ import com.alibaba.nacos.api.config.listener.Listener;
@RestController
@Slf4j
public class DipperPositionController {

RzlAccount rzlAccount;
@Value(value = "${position.hello}")
private String hello;
//RzlAccount rzlAccount;

@RequestMapping("/getPos")
public String getPos() throws NacosException, InterruptedException, IOException {
@@ -44,8 +46,7 @@ public class DipperPositionController {
// //log.info(positionId + ":" + content.positionId)
// Map<String, Object> dataMap = NacosDataParserHandler.getInstance().parseNacosData(content,"yaml");
// return dataMap == null ? "" : (String)dataMap.get(positionId);
String returnStr=
"return position = " + PositionConfig.getInstance().getHello() + "return name = " + PositionConfig.getInstance().getName();
String returnStr= "return position = " + hello;

return returnStr;
//return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString();


Yükleniyor…
İptal
Kaydet