Reputation: 691
How can we shutdown or stop a Spring application by itself programmatically?
We have currently using ConfigurableApplicationContext#close(), and yes, it does close the application but not shutdown or stop the application.
From the tomcat manager, the application status still is running, so the client still can connect to the web app and get the front-end resource. Besides, all servlets seems still working and can accept the request.
The below code shows how we do currently.
@Autowired
private ConfigurableApplicationContext configurableApplicationContext;
@Scheduled(cron="0 0/5 * * * ?")
private void validateLicenseExpired()
{
try
{
LicenseUtils.isLicensingPeriodValid();
} catch (LicenseInvalidException lie) {
logger.error("\t The licensing is expired", lie);
configurableApplicationContext.close();
}
}
Any help is appreciated.
Upvotes: 0
Views: 4472
Reputation: 4289
If its a boot application the you can use following link to stop the application.
Programmatically shut down Spring Boot application
Otherwise you can programmatically call the shutdown.sh like below to stop the server.
String command = "<path-to-tomcat>shutdown.sh"; // for windows use bat
Process child = Runtime.getRuntime().exec(command);
[Edit]
This thread explains about stoping application like tomcat manager
Start / stop a web application from itself?
Upvotes: 1