Browse Source

增加配置文件读取

tags/v1.0.0^2
林万龙 4 years ago
parent
commit
0e73159f60
2 changed files with 23 additions and 4 deletions
  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 View File

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


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


@Value("${hello}")
private String 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 View File

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


@Autowired
PositionConfig positionConfig;
RzlAccount rzlAccount;


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

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

Loading…
Cancel
Save