Improvement for Spring Boot Exit Codes

This commit is contained in:
Ali Dehghani 2020-08-09 11:38:50 +04:30
parent 87111ea998
commit 164957ad0a
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package com.baeldung.exitcode.exceptionexitgen;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class ExceptionExitCodeGeneratorApplication {
public static void main(String[] args) {
SpringApplication.run(ExceptionExitCodeGeneratorApplication.class, args);
}
@Bean
CommandLineRunner failApplication() {
return args -> {
throw new FailedToStartException();
};
}
}

View File

@ -0,0 +1,11 @@
package com.baeldung.exitcode.exceptionexitgen;
import org.springframework.boot.ExitCodeGenerator;
public class FailedToStartException extends RuntimeException implements ExitCodeGenerator {
@Override
public int getExitCode() {
return 127;
}
}