瀏覽代碼

增加配置文件读取

tags/v1.0.0^2
林万龙 3 年之前
父節點
當前提交
f4273be990
共有 2 個文件被更改,包括 12 次插入11 次删除
  1. +1
    -1
      src/main/java/com/telpo/dipperposition/config/PositionConfig.java
  2. +11
    -10
      src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java

+ 1
- 1
src/main/java/com/telpo/dipperposition/config/PositionConfig.java 查看文件

@@ -20,7 +20,7 @@ import org.springframework.context.annotation.Configuration;
@ConfigurationProperties(prefix = "position")
public class PositionConfig {

//@Value("${hello}")
@Value("${hello}")
private String hello;

}

+ 11
- 10
src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java 查看文件

@@ -32,7 +32,7 @@ public class DipperPositionController {
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
ConfigService configService = NacosFactory.createConfigService(properties);
String content = configService.getConfig(dataId, group, 5000);
String content = configService.getConfig(dataId, group, 10000);
System.out.println(content);
configService.addListener(dataId, group, new Listener() {
@Override
@@ -50,21 +50,22 @@ public class DipperPositionController {
log.info(String.valueOf(isPublishOk));
Thread.sleep(3000);

content = configService.getConfig(dataId, group, 5000);
configService = NacosFactory.createConfigService(properties);
content = configService.getConfig(dataId, group, 10000);
log.info(content);

content = configService.getConfig(positionId, group, 5000);
content = configService.getConfig(positionId, group, 10000);
log.info(content);

boolean isRemoveOk = configService.removeConfig(dataId, group);
log.info(String.valueOf(isRemoveOk));
Thread.sleep(3000);
//boolean isRemoveOk = configService.removeConfig(dataId, group);
//log.info(String.valueOf(isRemoveOk));
//Thread.sleep(3000);

content = configService.getConfig(dataId, group, 5000);
log.info(content);
Thread.sleep(30000);
//content = configService.getConfig(dataId, group, 10000);
//log.info(content);
//Thread.sleep(30000);

System.out.println(content);
//System.out.println(content);

return "Helle world!"; //ContextLoader.getCurrentWebApplicationContext().toString();
}


Loading…
取消
儲存