From f2088a1404167bfab7659f848a5a605d28adf926 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Tue, 12 Jan 2021 14:49:27 +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 --- .../telpo/dipperposition/config/PositionConfig.java | 11 +++++++++-- .../controller/DipperPositionController.java | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index 4285ce0..223c64e 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/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; diff --git a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java b/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java index 24b744a..22cba9b 100644 --- a/src/main/java/com/telpo/dipperposition/controller/DipperPositionController.java +++ b/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(); }