Reputation: 86845
I'm using apache prunsrv
service to install a jar
as a windows service.
When the service is shut down, the application crashes.
set PR_STARTMETHOD=main
set PR_STOPMETHOD=exit
My startup and shutdown class looks as follows:
public class TravelportMainApp {
private static ConfigurableApplicationContext ctx;
public static void main(String[] args) {
ctx = SpringApplication.run(source, args);
ctx.registerShutdownHook();
}
public static void exit(String[] args) throws InterruptedException {
if (ctx != null && ctx instanceof AbstractApplicationContext) {
((AbstractApplicationContext) ctx).destroy();
}
Sysout("EXIT OK.");
}
}
Result: the exit command "EXIT OK" is printed, but then the command line app crashed saying "commons daemon service runner is not working anymore.". What could be wrong here?
Upvotes: 2
Views: 548
Reputation: 86845
I ended up as follows:
public static void exit(String[] args) throws InterruptedException {
SpringApplication.exit(ctx);
System.exit(0);
}
Upvotes: 1