package com.xxx.global;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class GlobalCommandLineRunner implements CommandLineRunner {
public void run(String... args) throws Exception {
// 在应用程序启动时执行的代码
System.out.println("应用程序已启动");
// 注册JVM关闭事件处理器
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
// 在应用程序关闭前执行的代码
System.out.println("应用程序将要关闭");
}));
}
}