diff --git a/caf-bootstrap/src/main/java/io/iec/edp/caf/CAFBootstrap.java b/caf-bootstrap/src/main/java/io/iec/edp/caf/CAFBootstrap.java index 6b9f7684486a65f292631428d00501927760b9b4..5778c493cbdcc4075234e8884784c8408b7e0274 100644 --- a/caf-bootstrap/src/main/java/io/iec/edp/caf/CAFBootstrap.java +++ b/caf-bootstrap/src/main/java/io/iec/edp/caf/CAFBootstrap.java @@ -19,6 +19,7 @@ package io.iec.edp.caf; import io.iec.edp.caf.autoconfigure.EnvironmentPreparedConfiguration; import io.iec.edp.caf.autoconfigure.PackageScanConfiguration; +import io.iec.edp.caf.common.JSONSerializer; import io.iec.edp.caf.commons.event.StartupCompletedEvent; import io.iec.edp.caf.commons.event.StartupCompletedTask; import io.iec.edp.caf.commons.runtime.CafEnvironment; @@ -43,6 +44,11 @@ import org.springframework.core.Ordered; import org.springframework.lang.NonNull; import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -77,23 +83,45 @@ public class CAFBootstrap { AppManager.enableAppManager(Thread.currentThread()); } //启动程序 - context = springApplication.run(args); - beanFactory = context.getBeanFactory(); - //输出启动日志 StartupInfoLogger.logStarted(beanFactory); - //设置临时目录 setTempDir(); - + recordDuStartInfo(); //触发事件 StartupEventPublisher eventPublisher = beanFactory.getBean(StartupEventPublisher.class); eventPublisher.onStartupCompleted(new StartupCompletedEvent(new StartupCompletedTask())); //todo 兼容老的启动后事件 eventPublisher.onStartupCompleted(new io.iec.edp.caf.boot.event.startup.StartupCompletedEvent(new StartupCompletedTask())); } + private static void recordDuStartInfo() { + var duName = System.getProperty("deployment-unit.name"); + if (duName != null && duName.length() > 0) { + String serverPath = CafEnvironment.getBasePath(); + + Map map = new HashMap(); + if (duName != null && duName.length() > 0) { + map.put(duName, "true"); + } + String json = JSONSerializer.serialize(map); + Path jsonFilePath = Paths.get(serverPath, new String[] { "logs", duName, "start.json" }); + + try { + if (!Files.exists(jsonFilePath)) { + + if (!Files.exists(jsonFilePath.getParent())) { + Files.createDirectories(jsonFilePath.getParent()); + } + Files.createFile(jsonFilePath); + } + Files.write(jsonFilePath, json.getBytes(StandardCharsets.UTF_8)); + } catch (IOException e) { + log.error("Writing file error:", e); + } + } + } @Bean @ConditionalOnProperty("caf-boot.server.allow-bean-initialization-time-tracking")