diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 18ae574f58c..54109b24f0e 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -336,8 +336,31 @@ callbacks (such as the `DisposableBean` interface, or the `@PreDestroy` annotati be used. In addition, beans may implement the `org.springframework.boot.ExitCodeGenerator` -interface if they wish to return a specific exit code when the application ends. +interface if they wish to return a specific exit code when `SpringApplication.exit()` +is called. This exit code can then be passed to `System.exit()` to return it as a status +code. +[source,java,indent=0] +---- + @SpringBootApplication + public class ExitCodeApplication { + + public static void main(String[] args) { + System.exit(SpringApplication.exit( + SpringApplication.run(ExitCodeApplication.class, args))); + } + + @Bean + public ExitCodeGenerator exitCodeGenerator(){ + return () -> 42; + } + + } +---- + +Also, the `ExitCodeGenerator` interface may be implemented by exceptions. When such an +exception is encountered, Spring Boot will return the exit code provided by the +implemented `getExitCode()` method. [[boot-features-application-admin]] diff --git a/spring-boot/src/main/java/org/springframework/boot/ExitCodeGenerator.java b/spring-boot/src/main/java/org/springframework/boot/ExitCodeGenerator.java index 03dc375a16b..33b82292691 100644 --- a/spring-boot/src/main/java/org/springframework/boot/ExitCodeGenerator.java +++ b/spring-boot/src/main/java/org/springframework/boot/ExitCodeGenerator.java @@ -18,8 +18,7 @@ package org.springframework.boot; /** * Interface used to generate an 'exit code' from a running command line - * {@link SpringApplication}. Since 1.3.2 this interface can be used on exceptions as well - * as directly on beans. + * {@link SpringApplication}. Can be used on exceptions as well as directly on beans. * * @author Dave Syer * @see SpringApplication#exit(org.springframework.context.ApplicationContext,