From 0e73159f60a4c261d247ff3e55ed5e776aa336ea Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:29:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../telpo/dipperposition/co/RzlAccount.java | 21 +++++++++++++++++++ .../controller/DipperPositionController.java | 6 ++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java b/src/main/java/com/telpo/dipperposition/co/RzlAccount.java index 709f4da..df5d1bc 100644 --- a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java +++ b/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; + } } diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index f69f1ec..d31777a 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/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 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(); } }