From 0f95841bde845f609706509c81c9819a211b293a Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 11:55:30 +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 --- .../dipperposition/config/PositionConfig.java | 7 +++- .../controller/DipperPositionController.java | 40 ++----------------- 2 files changed, 9 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 78fefbd..ed1f84e 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -1,5 +1,8 @@ package com.telpo.dipperposition.config; +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.api.config.ConfigService; import lombok.Getter; import lombok.Setter; import lombok.ToString; @@ -7,6 +10,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import java.util.Properties; + /** * @program: gateway * @description: jwt设置 @@ -20,7 +25,7 @@ import org.springframework.context.annotation.Configuration; @ConfigurationProperties(prefix = "position") public class PositionConfig { - @Value("${hello}") + //@Value("${hello}") 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 74d6b59..308655c 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java @@ -24,48 +24,14 @@ public class DipperPositionController { @RequestMapping("/getPos") public String getPos() throws NacosException, InterruptedException { - String serverAddr = "localhost"; - String dataId = "dipperposition-service-dev"; String group = "DEFAULT_GROUP"; - - String positionId = "String.hello"; + 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); + String content = configService.getConfig(positionId, group, 10000); System.out.println(content); - configService.addListener(dataId, group, new Listener() { - @Override - public void receiveConfigInfo(String configInfo) { - log.info("recieve:" + configInfo); - } - - @Override - public Executor getExecutor() { - return null; - } - }); - - boolean isPublishOk = configService.publishConfig(dataId, group, "content"); - log.info(String.valueOf(isPublishOk)); - Thread.sleep(3000); - - configService = NacosFactory.createConfigService(properties); - content = configService.getConfig(dataId, group, 10000); - log.info(content); - - content = configService.getConfig(positionId, group, 10000); - log.info(content); - - //boolean isRemoveOk = configService.removeConfig(dataId, group); - //log.info(String.valueOf(isRemoveOk)); - //Thread.sleep(3000); - - //content = configService.getConfig(dataId, group, 10000); - //log.info(content); - //Thread.sleep(30000); - - //System.out.println(content); return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString(); }