浏览代码

增加配置文件读取

tags/v1.0.0^2
林万龙 4 年前
父节点
当前提交
0f95841bde
共有 2 个文件被更改,包括 9 次插入38 次删除
  1. +6
    -1
      src/main/java/com/telpo/dipperposition/config/PositionConfig.java
  2. +3
    -37
      src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java

+ 6
- 1
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;

}

+ 3
- 37
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();
}


正在加载...
取消
保存