deason 4 år sedan
förälder
incheckning
4071a0db87

+ 6 - 1
config-center-client/src/main/java/cn/com/qmth/framework/config/center/client/core/CustomEnvironmentPostProcessor.java

@@ -40,7 +40,12 @@ public class CustomEnvironmentPostProcessor implements CustomConfigProcessor, En
 
         CustomMapPropertySource customMapPropertySource = new CustomMapPropertySource(ConfigConstants.CUSTOM_PROPERTY_SOURCE, remoteProperties);
         environment.getPropertySources().addLast(customMapPropertySource);
-        // this.printPropertySources(environment.getPropertySources());
+
+        EnvProperty.initEnvironment(environment);
+
+        if (environment.getProperty("debug", Boolean.class, false)) {
+            this.printPropertySources(environment.getPropertySources());
+        }
     }
 
     @Override

+ 64 - 0
config-center-client/src/main/java/cn/com/qmth/framework/config/center/client/core/EnvProperty.java

@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2021 the original author, All Rights Reserved.
+ * Created by Deason on 2021-05-10 20:37:57
+ */
+
+package cn.com.qmth.framework.config.center.client.core;
+
+import org.springframework.core.env.ConfigurableEnvironment;
+
+/**
+ * 环境配置项
+ *
+ * @author: Deason
+ * @since: 2021/5/10
+ */
+public final class EnvProperty {
+
+    private static ConfigurableEnvironment ENVIRONMENT;
+
+    private EnvProperty() {
+
+    }
+
+    static void initEnvironment(ConfigurableEnvironment environment) {
+        if (environment == null) {
+            throw new IllegalArgumentException("environment must be not null");
+        }
+
+        if (ENVIRONMENT != null) {
+            return;
+        }
+
+        ENVIRONMENT = environment;
+    }
+
+    public static boolean containsProperty(String key) {
+        return ENVIRONMENT.containsProperty(key);
+    }
+
+    public static String getProperty(String key) {
+        return ENVIRONMENT.getProperty(key);
+    }
+
+    public static String getProperty(String key, String defaultValue) {
+        return ENVIRONMENT.getProperty(key, defaultValue);
+    }
+
+    public static <T> T getProperty(String key, Class<T> targetType) {
+        return ENVIRONMENT.getProperty(key, targetType);
+    }
+
+    public static <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
+        return ENVIRONMENT.getProperty(key, targetType, defaultValue);
+    }
+
+    public static String getRequiredProperty(String key) throws IllegalStateException {
+        return ENVIRONMENT.getRequiredProperty(key);
+    }
+
+    public static <T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException {
+        return ENVIRONMENT.getRequiredProperty(key, targetType);
+    }
+
+}