I have a Spring Boot web application running in docker.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Even if I define an ExitCodeGenerator I cannot override the exit code
@Bean
public ExitCodeGenerator exitCodeGenerator() {
return () -> 0;
}
@Bean
public ApplicationListener applicationListener() {
return applicationEvent -> {
logger.info("*** Event {}", applicationEvent);
if (applicationEvent instanceof ExitCodeEvent) {
logger.info("---> ExitCode={}", ((ExitCodeEvent) applicationEvent).getExitCode());
}
};
}
It seems that the shutdown of the application is somehow handled differently. Main reason for changing the exit code is dockers restart functionality. If I stop my application it stops with exit code 142. Default behaviour for java applications. But If I now restart docker or the server docker automatically starts the application because all containers with an exit code > 0 are started.
Thanks for your answers.