parent
cf2ebbcb25
commit
e2880ee2c3
|
@ -337,29 +337,30 @@ be used.
|
||||||
|
|
||||||
In addition, beans may implement the `org.springframework.boot.ExitCodeGenerator`
|
In addition, beans may implement the `org.springframework.boot.ExitCodeGenerator`
|
||||||
interface if they wish to return a specific exit code when `SpringApplication.exit()`
|
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]
|
[source,java,indent=0]
|
||||||
----
|
----
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class ExitCodeApplication {
|
public class ExitCodeApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.exit(SpringApplication.exit(SpringApplication.run(ExitCodeApplication.class, args)));
|
System.exit(SpringApplication.exit(
|
||||||
}
|
SpringApplication.run(ExitCodeApplication.class, args)));
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ExitCodeGenerator exitCodeGenerator(){
|
public ExitCodeGenerator exitCodeGenerator(){
|
||||||
return () -> 42;
|
return () -> 42;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
Also, the `ExitCodeGenerator` interface may be implemented by exceptions. When such an exception is
|
Also, the `ExitCodeGenerator` interface may be implemented by exceptions. When such an
|
||||||
encountered, Spring Boot will return the exit code provided by the implemented `getExitCode()` method
|
exception is encountered, Spring Boot will return the exit code provided by the
|
||||||
to the outside caller.
|
implemented `getExitCode()` method.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[boot-features-application-admin]]
|
[[boot-features-application-admin]]
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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
|
* 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
|
* {@link SpringApplication}. Can be used on exceptions as well as directly on beans.
|
||||||
* as directly on beans.
|
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @see SpringApplication#exit(org.springframework.context.ApplicationContext,
|
* @see SpringApplication#exit(org.springframework.context.ApplicationContext,
|
||||||
|
|
Loading…
Reference in New Issue