package com.wms_main;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * 系统启动类
 */
@SpringBootApplication
public class WmsMainApplication {

	/**
	 * 用于重启程序的上下文
	 */
	private static ConfigurableApplicationContext context;

	/**
	 * 主函数，程序的入口
	 *
	 * @param args 命令行参数，以字符串数组形式传入
	 */
	public static void main(String[] args) {
		context = SpringApplication.run(WmsMainApplication.class, args);
	}

	/**
	 * 重启程序
	 */
	public static void restart() {
		ApplicationArguments args = context.getBean(ApplicationArguments.class);
		Thread thread = new Thread(() -> {
			context.close();
			context = SpringApplication.run(WmsMainApplication.class, args.getSourceArgs());
		});
		thread.setDaemon(false);
		thread.start();
	}
}
