Ver código fonte

增加配置文件读取

tags/v1.0.0^2
林万龙 3 anos atrás
pai
commit
f2088a1404
2 arquivos alterados com 10 adições e 2 exclusões
  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 Ver arquivo

@@ -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 Ver arquivo

@@ -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();
}


Carregando…
Cancelar
Salvar