瀏覽代碼

增加配置文件读取

tags/v1.0.0^2
林万龙 3 年之前
父節點
當前提交
f2088a1404
共有 2 個檔案被更改,包括 10 行新增2 行删除
  1. +9
    -2
      src/main/java/com/telpo/dipperposition/config/PositionConfig.java
  2. +1
    -0
      src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java

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

@@ -7,9 +7,11 @@ import com.telpo.dipperposition.co.RzlAccount;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
@@ -28,14 +30,19 @@ import java.util.Properties;
@ToString
@Configuration
public class PositionConfig {
@Value(value = "${position.hello}")

@Autowired
private ConfigurableApplicationContext configurableApplicationContext;
//@Value(value = "${position.hello}")
private String hello;

@Value(value = "${spring.application.name}")
//@Value(value = "${spring.application.name}")
private String name;

PositionConfig()
{
hello = configurableApplicationContext.getEnvironment().getProperty("position.hello");
name = configurableApplicationContext.getEnvironment().getProperty("spring.application.name");
}

private static PositionConfig instance;


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

@@ -46,6 +46,7 @@ public class DipperPositionController {
// return dataMap == null ? "" : (String)dataMap.get(positionId);
String returnStr=
"return position = " + PositionConfig.getInstance().getHello() + "return name = " + PositionConfig.getInstance().getName();

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


Loading…
取消
儲存