30 lines
977 B
Java
30 lines
977 B
Java
|
package com.baeldung.restart;
|
||
|
|
||
|
import org.springframework.boot.ApplicationArguments;
|
||
|
import org.springframework.boot.SpringApplication;
|
||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||
|
|
||
|
@SpringBootApplication
|
||
|
public class Application extends SpringBootServletInitializer {
|
||
|
|
||
|
private static ConfigurableApplicationContext context;
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
context = SpringApplication.run(Application.class, args);
|
||
|
}
|
||
|
|
||
|
public static void restart() {
|
||
|
ApplicationArguments args = context.getBean(ApplicationArguments.class);
|
||
|
|
||
|
Thread thread = new Thread(() -> {
|
||
|
context.close();
|
||
|
context = SpringApplication.run(Application.class, args.getSourceArgs());
|
||
|
});
|
||
|
|
||
|
thread.setDaemon(false);
|
||
|
thread.start();
|
||
|
}
|
||
|
|
||
|
}
|