[英]Restarting Java Spring Boot Application
first of all i just want to tell that i already read multiple methods and none of them is working for me.首先,我只想告诉我,我已经阅读了多种方法,但没有一个对我有用。 All i need is just restart the application whenever i call method.
我只需要在调用方法时重新启动应用程序。
what i have tried so far:到目前为止我所尝试的:
@Service
public class RestartService {
@Autowired
private RestartEndpoint restartEndpoint;
public void restartApp() {
Thread restartThread = new Thread(() -> restartEndpoint.restart());
restartThread.setDaemon(false);
restartThread.start();
}
}
another one:另一个:
@SpringBootApplication
public class RestfulWebservicesApplication {
private static ConfigurableApplicationContext context;
public static void main(String[] args) throws IOException {
SpringApplication.run(RestfulWebservicesApplication.class, args);
}
public static void restart() {
ApplicationArguments args = context.getBean(ApplicationArguments.class);
Thread thread = new Thread(() -> {
context.close();
context = SpringApplication.run(RestfulWebservicesApplication.class, args.getSourceArgs());
});
thread.setDaemon(false);
thread.start();
}
}
and this:和这个:
public class OneMoreRestart {
@GetMapping("/restart")
void restart() {
Thread restartThread = new Thread(() -> {
try {
Thread.sleep(1000);
Main.restart();
} catch (InterruptedException ignored) {
}
});
restartThread.setDaemon(false);
restartThread.start();
}
}
also i tried methods that were posted here: https://www.baeldung.com/java-restart-spring-boot-app我也尝试了这里发布的方法: https://www.baeldung.com/java-restart-spring-boot-app
i have tried all the methods that i found in google or here none of them are working for me....我已经尝试了我在谷歌或这里找到的所有方法,它们都不适合我....
i usually get nullpointer exception, im guys i know im a complete noob but i never tought that restarting the application might be so hard.我通常会得到空指针异常,我知道我是一个完整的菜鸟,但我从不认为重新启动应用程序可能会如此困难。 What am i missing here or what am i doing here wrong????
我在这里错过了什么或者我在这里做错了什么????
you need to modify it as shown below您需要修改它,如下所示
public static void main(String[] args) throws IOException {
context = SpringApplication.run(RestfulWebservicesApplication.class, args);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.