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