[WIP][Fix] The initialization of the configuration comes before the bean is loaded (#3529)

* fix: Configuration initialization should be done before the springboot startup bean is loaded
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/StreamParkConsoleBootstrap.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/StreamParkConsoleBootstrap.java
index a9e3bf3..ac6c2c1 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/StreamParkConsoleBootstrap.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/StreamParkConsoleBootstrap.java
@@ -17,9 +17,11 @@
 
 package org.apache.streampark.console;
 
+import org.apache.streampark.console.core.runner.EnvApplicationContextInitializer;
+
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
 /**
@@ -47,6 +49,8 @@
 public class StreamParkConsoleBootstrap {
 
   public static void main(String[] args) {
-    SpringApplication.run(StreamParkConsoleBootstrap.class, args);
+    new SpringApplicationBuilder(StreamParkConsoleBootstrap.class)
+        .initializers(new EnvApplicationContextInitializer())
+        .run(args);
   }
 }
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvApplicationContextInitializer.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvApplicationContextInitializer.java
new file mode 100644
index 0000000..969766d
--- /dev/null
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvApplicationContextInitializer.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.streampark.console.core.runner;
+
+import org.apache.streampark.common.conf.ConfigKeys;
+import org.apache.streampark.common.conf.InternalConfigHolder;
+import org.apache.streampark.common.conf.InternalOption;
+import org.apache.streampark.common.util.Utils;
+import org.apache.streampark.console.base.util.WebUtils;
+
+import org.apache.commons.lang3.StringUtils;
+
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.Environment;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+public class EnvApplicationContextInitializer
+    implements ApplicationContextInitializer<ConfigurableApplicationContext> {
+
+  @Override
+  public void initialize(ConfigurableApplicationContext context) {
+    Optional<String> profile =
+        Arrays.stream(context.getEnvironment().getActiveProfiles()).findFirst();
+    if ("test".equals(profile.orElse(null))) {
+      return;
+    }
+
+    String appHome = WebUtils.getAppHome();
+    if (StringUtils.isBlank(appHome)) {
+      throw new ExceptionInInitializerError(
+          String.format(
+              "[StreamPark] System initialization check failed,"
+                  + " The system initialization check failed. If started local for development and debugging,"
+                  + " please ensure the -D%s parameter is clearly specified,"
+                  + " more detail: https://streampark.apache.org/docs/user-guide/deployment",
+              ConfigKeys.KEY_APP_HOME()));
+    }
+
+    // init InternalConfig
+    initInternalConfig(context.getEnvironment());
+  }
+
+  private void initInternalConfig(Environment springEnv) {
+    // override config from spring application.yaml
+    InternalConfigHolder.keys().stream()
+        .filter(springEnv::containsProperty)
+        .forEach(
+            key -> {
+              InternalOption config = InternalConfigHolder.getConfig(key);
+              Utils.requireNotNull(config);
+              InternalConfigHolder.set(config, springEnv.getProperty(key, config.classType()));
+            });
+  }
+}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvInitializer.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvInitializer.java
index 5026ee3..9f6cd80 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvInitializer.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/runner/EnvInitializer.java
@@ -20,7 +20,6 @@
 import org.apache.streampark.common.conf.CommonConfig;
 import org.apache.streampark.common.conf.ConfigKeys;
 import org.apache.streampark.common.conf.InternalConfigHolder;
-import org.apache.streampark.common.conf.InternalOption;
 import org.apache.streampark.common.conf.Workspace;
 import org.apache.streampark.common.enums.StorageType;
 import org.apache.streampark.common.fs.FsOperator;
@@ -41,7 +40,6 @@
 import org.springframework.boot.ApplicationRunner;
 import org.springframework.context.ApplicationContext;
 import org.springframework.core.annotation.Order;
-import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Component;
 
 import java.io.File;
@@ -50,7 +48,6 @@
 import java.nio.file.Files;
 import java.util.Arrays;
 import java.util.HashSet;
-import java.util.Optional;
 import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -78,25 +75,8 @@
   @SneakyThrows
   @Override
   public void run(ApplicationArguments args) throws Exception {
-    Optional<String> profile =
-        Arrays.stream(context.getEnvironment().getActiveProfiles()).findFirst();
-    if ("test".equals(profile.orElse(null))) {
-      return;
-    }
-
-    String appHome = WebUtils.getAppHome();
-    if (StringUtils.isBlank(appHome)) {
-      throw new ExceptionInInitializerError(
-          String.format(
-              "[StreamPark] System initialization check failed,"
-                  + " The system initialization check failed. If started local for development and debugging,"
-                  + " please ensure the -D%s parameter is clearly specified,"
-                  + " more detail: https://streampark.apache.org/docs/user-guide/deployment",
-              ConfigKeys.KEY_APP_HOME()));
-    }
-
     // init InternalConfig
-    initInternalConfig(context.getEnvironment());
+    initInternalConfig();
     // overwrite system variable HADOOP_USER_NAME
     String hadoopUserName = InternalConfigHolder.get(CommonConfig.STREAMPARK_HADOOP_USER_NAME());
     overrideSystemProp(ConfigKeys.KEY_HADOOP_USER_NAME(), hadoopUserName);
@@ -106,17 +86,7 @@
     ZIOExt.unsafeRun(EmbeddedFileServer.launch());
   }
 
-  private void initInternalConfig(Environment springEnv) {
-    // override config from spring application.yaml
-    InternalConfigHolder.keys().stream()
-        .filter(springEnv::containsProperty)
-        .forEach(
-            key -> {
-              InternalOption config = InternalConfigHolder.getConfig(key);
-              Utils.requireNotNull(config);
-              InternalConfigHolder.set(config, springEnv.getProperty(key, config.classType()));
-            });
-
+  private void initInternalConfig() {
     settingService.getMavenConfig().updateConfig();
 
     InternalConfigHolder.log();