Skip to content

Commit e0a1fe9

Browse files
committed
Merge branch '1.5.x'
2 parents f4d3e49 + 54a13cb commit e0a1fe9

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,31 @@ callbacks (such as the `DisposableBean` interface, or the `@PreDestroy` annotati
336336
be used.
337337

338338
In addition, beans may implement the `org.springframework.boot.ExitCodeGenerator`
339-
interface if they wish to return a specific exit code when the application ends.
339+
interface if they wish to return a specific exit code when `SpringApplication.exit()`
340+
is called. This exit code can then be passed to `System.exit()` to return it as a status
341+
code.
340342

343+
[source,java,indent=0]
344+
----
345+
@SpringBootApplication
346+
public class ExitCodeApplication {
347+
348+
public static void main(String[] args) {
349+
System.exit(SpringApplication.exit(
350+
SpringApplication.run(ExitCodeApplication.class, args)));
351+
}
352+
353+
@Bean
354+
public ExitCodeGenerator exitCodeGenerator(){
355+
return () -> 42;
356+
}
357+
358+
}
359+
----
360+
361+
Also, the `ExitCodeGenerator` interface may be implemented by exceptions. When such an
362+
exception is encountered, Spring Boot will return the exit code provided by the
363+
implemented `getExitCode()` method.
341364

342365

343366
[[boot-features-application-admin]]

spring-boot/src/main/java/org/springframework/boot/ExitCodeGenerator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
/**
2020
* Interface used to generate an 'exit code' from a running command line
21-
* {@link SpringApplication}. Since 1.3.2 this interface can be used on exceptions as well
22-
* as directly on beans.
21+
* {@link SpringApplication}. Can be used on exceptions as well as directly on beans.
2322
*
2423
* @author Dave Syer
2524
* @see SpringApplication#exit(org.springframework.context.ApplicationContext,

0 commit comments

Comments
 (0)