浏览代码

增加配置文件读取

tags/v1.0.0^2
林万龙 4 年前
父节点
当前提交
0e73159f60
共有 2 个文件被更改,包括 23 次插入4 次删除
  1. +21
    -0
      src/main/java/com/telpo/dipperposition/co/RzlAccount.java
  2. +2
    -4
      src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java

+ 21
- 0
src/main/java/com/telpo/dipperposition/co/RzlAccount.java 查看文件

@@ -3,6 +3,8 @@ package com.telpo.dipperposition.co;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

/**
@@ -11,11 +13,30 @@ import org.springframework.stereotype.Component;
* @author: king
* @create: 2021-01-12 14:02
**/
@Lazy
@Getter
@Setter
@ToString
@Component
public class RzlAccount {

@Value("${hello}")
private String hello;

RzlAccount()
{
}

private static RzlAccount instance;
public static RzlAccount getInstance(){
if (instance==null){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
instance = new RzlAccount();
}
return instance;
}
}

+ 2
- 4
src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java 查看文件

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

@Autowired
PositionConfig positionConfig;
RzlAccount rzlAccount;

@RequestMapping("/getPos")
public String getPos() throws NacosException, InterruptedException, IOException {
@@ -45,8 +44,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);

return positionConfig.getHello();
return RzlAccount.getInstance().getHello();
//return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString();
}
}

正在加载...
取消
保存