I am trying to programmatically restart my Spring Application without having the user to intervene.
Basically, I have a page which allows to switch the mode of the a
You can use the RestartEndPoint (in spring-cloud-context dependency) to restart the Spring Boot application programmatically:
@Autowired
private RestartEndpoint restartEndpoint;
...
Thread restartThread = new Thread(() -> restartEndpoint.restart());
restartThread.setDaemon(false);
restartThread.start();
It works, even though it will throw an exception to inform you that this may lead to memory leaks:
The web application [xyx] appears to have started a thread named [Thread-6] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
The same answer was provided for this other question (worded differently): Call Spring actuator /restart endpoint from Spring boot using a java function