package ru.mtuci.messenger.migrate; import org.springframework.boot.SpringApplication; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; @Component @Profile("migrate") public class MigrateExit implements ApplicationRunner { private final ConfigurableApplicationContext context; public MigrateExit(ConfigurableApplicationContext context) { this.context = context; } @Override public void run(ApplicationArguments args) { Thread exit = new Thread(() -> { try { Thread.sleep(500); } catch (InterruptedException interrupted) { Thread.currentThread().interrupt(); } int code = SpringApplication.exit(context, () -> 0); System.exit(code); }, "migrate-exit"); exit.setDaemon(false); exit.start(); } }