Reputation: 1051
I have written a Spring Boot + Spring Batch application in IntelliJ that fails on startup if it faces any configuration issues, which is expected. But the exit code of the application shown in IntelliJ is still 0. Doesn't a 0 error code imply success? What should I do to have the application return the correct exit code?
Upvotes: 3
Views: 2262
Reputation: 11337
After a lot of digging I've found that adding the spring-boot-devtools
means that Spring will exit with 0 if it's misconfigured. See here: https://github.com/spring-projects/spring-boot/issues/28541
Upvotes: 0
Reputation: 11337
This is surprisingly awkward to do! SpringApplication.run()
has a very bizzare startup procedure, that involves spawning a new thread to do the work and yada yada. In the process of doing this it calls SilentExitExceptionHandler.setup(thread)
which has the side effect of ensuring any exit code is always 0!
If you want to work around this you can either splat the uncaught exception handler.
You can also do this:
try {
SpringApplication.run(...);
}
catch(RuntimeException ex) {
throw new RuntimeException(ex);
}
By wrapping the exception, spring doesn't recognise it as a special exception and so will exit with an error code of 1. However there are side effects - notably it will log the exception to stderr, but it will also ignore any ExitCodeGenerator
beans you have setup.
Upvotes: 1
Reputation: 1319
If you've programmed it to exit, it might still be 0. You can customize it by building a ExitCodeGenerator.
http://www.logicbig.com/tutorials/spring-framework/spring-boot/app-exit-code/
Upvotes: 0