From cf2ebbcb2559ade0ae78b1d63b00b68656a12933 Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Wed, 12 Jul 2017 22:43:18 +0200 Subject: [PATCH 1/2] Improve ExitCodeGenerator doc See gh-9740 --- .../main/asciidoc/spring-boot-features.adoc | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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 3ecca74b92..cfc5363ca2 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -336,7 +336,29 @@ 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 pass it to the outside. + +[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 +to the outside caller. From e2880ee2c3c91e5872b91328c1d54cc5a3b91dd9 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 13 Jul 2017 09:21:36 +0200 Subject: [PATCH 2/2] Polish "Improve ExitCodeGenerator doc" Closes gh-9740 --- .../main/asciidoc/spring-boot-features.adoc | 29 ++++++++++--------- .../boot/ExitCodeGenerator.java | 5 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) 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 cfc5363ca2..e3464392c4 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -337,29 +337,30 @@ be used. In addition, beans may implement the `org.springframework.boot.ExitCodeGenerator` 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 pass it to the outside. +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 class ExitCodeApplication { - public static void main(String[] args) { - System.exit(SpringApplication.exit(SpringApplication.run(ExitCodeApplication.class, args))); - } + public static void main(String[] args) { + System.exit(SpringApplication.exit( + SpringApplication.run(ExitCodeApplication.class, args))); + } - @Bean - public ExitCodeGenerator exitCodeGenerator(){ - return () -> 42; - } + @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 -to the outside caller. - +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 20b7ec7bed..fb4bd5dd7f 100644 --- a/spring-boot/src/main/java/org/springframework/boot/ExitCodeGenerator.java +++ b/spring-boot/src/main/java/org/springframework/boot/ExitCodeGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -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,