From 558005fd9aace61def5c80bff197d0c459994651 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:14:46 +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 | 2 ++ .../controller/DipperPositionController.java | 30 +++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java b/src/main/java/com/telpo/dipperposition/co/RzlAccount.java index d332dd6..709f4da 100644 --- a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java +++ b/src/main/java/com/telpo/dipperposition/co/RzlAccount.java @@ -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; diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index 1202dc6..157fc25 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -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 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 dataMap = NacosDataParserHandler.getInstance().parseNacosData(content,"yaml"); +// return dataMap == null ? "" : (String)dataMap.get(positionId); + + return rzlAccount.getHello(); //return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); } }