package org.wcs;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.wcs.utils.SpringUtils;

@Import(SpringUtils.class)
@EnableTransactionManagement
@SpringBootApplication
public class WcsApplication {

    private static ConfigurableApplicationContext applicationContext;

	public static void main(String[] args) {
        applicationContext = SpringApplication.run(WcsApplication.class, args);
    }

    /**
     * 退出并重启
     */
    public static void restart() {
        ApplicationArguments args = applicationContext.getBean(ApplicationArguments.class);
        Thread thread = new Thread(() -> {
            applicationContext.close();
            applicationContext = SpringApplication.run(WcsApplication.class, args.getSourceArgs()); // 修改这里
        });
        thread.setDaemon(false);
        thread.start();
    }


}
