|
@@ -0,0 +1,51 @@
|
|
|
|
|
+package com.jzg.organization;
|
|
|
|
|
+
|
|
|
|
|
+import jakarta.annotation.Resource;
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
+import org.springframework.boot.CommandLineRunner;
|
|
|
|
|
+import org.springframework.core.env.ConfigurableEnvironment;
|
|
|
|
|
+import org.springframework.core.env.EnumerablePropertySource;
|
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.stream.StreamSupport;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 打印系统中所有的变量
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author lipf
|
|
|
|
|
+ * @date 2026/4/27 17:28
|
|
|
|
|
+ */
|
|
|
|
|
+@Component
|
|
|
|
|
+public class PrintEnvRunner implements CommandLineRunner {
|
|
|
|
|
+
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(PrintEnvRunner.class);
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private ConfigurableEnvironment env;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run(String... args) throws Exception {
|
|
|
|
|
+ log.info("====== 开始打印所有环境变量与配置项 ======");
|
|
|
|
|
+
|
|
|
|
|
+ // 获取所有属性源
|
|
|
|
|
+ StreamSupport.stream(env.getPropertySources().spliterator(), false)
|
|
|
|
|
+ .filter(ps -> ps instanceof EnumerablePropertySource)
|
|
|
|
|
+ .map(ps -> ((EnumerablePropertySource<?>) ps).getPropertyNames())
|
|
|
|
|
+ .flatMap(Arrays::stream)
|
|
|
|
|
+ .distinct() // 去重
|
|
|
|
|
+ .sorted() // 排序
|
|
|
|
|
+ .forEach(key -> {
|
|
|
|
|
+ // ⚠️ 安全提示:建议过滤掉敏感信息,如密码、密钥等
|
|
|
|
|
+// if (key.toLowerCase().contains("password") || key.toLowerCase().contains("secret")) {
|
|
|
|
|
+// log.info("{} = ****** (Sensitive)", key);
|
|
|
|
|
+// } else {
|
|
|
|
|
+// log.info("{} = {}", key, env.getProperty(key));
|
|
|
|
|
+// }
|
|
|
|
|
+ log.info("{} = {}", key, env.getProperty(key));
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ log.info("====== 打印结束 ======");
|
|
|
|
|
+ }
|
|
|
|
|
+}
|