. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/,
The information comes from the static constant BANNER of the SpringBootBanner class , which is a string array. When no banner attribute is specified, the console outputs the array data by default. We can change the output of the banner through the powerful configuration functions provided by Spring Boot .
1. Set by code
Create a SpringApplication object in the main method, and set the banner property through the instance object,
public static void main(String[] args) { SpringApplication app = new SpringApplication(SpringBootSimpleApplication.class); app.setBanner(new Banner() { @Override public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) { out.print("\n\n\tSpring Boot Sample App!\n\n".toUpperCase()); } }); app.run(args); }
Run the main method, the console will print out the customized banner information:
SPRING BOOT SAMPLE APP!
2017-04-06 17:10:14.954 INFO 9808 --- [ main] the.spring.SpringBootSimpleApplication
……
2. By defining a text file
You can generate personalized text in the "Text to ASCII Art Generator" of the http://patorjk.com website as the banner of the project and save it in the banner.txt file, and then place the banner.txt file in the project's src/ In the main/resources directory, Spring Boot will load the banner file in this path when the project starts. In addition, the properties file will override the settings in the main method. The effect is as follows:
___ _ ___ _
/ __|_ __ _ _(_)_ _ __ _ | _ ) ___ ___| |_
\__ \ '_ \ '_| | ' \/ _` | | _ \/ _ \/ _ \ _|
|___/ .__/_| |_|_||_\__, | |___/\___/\___/\__|
|_| |___/
2017-04-06 17:29:26.012 INFO 1668 --- [ main] the.spring.SpringBootSimpleApplication
……
Spring Boot loads the banner.txt (default file name) file in the resources directory by default. You can also load the banner file at runtime by setting the banner.location property value: --banner.location=classpath:/META-INF/banner.txt , you can also set banner.location=classpath:/META-INF/banner.txt in the application.properties file. When configuring with property values, the name of banner.txt can be customized
3. Turn off the banner display
In the program, you can use app.setBannerMode(Mode.OFF); to turn off the banner, and use the property value to set: spring.main.banner-mode=off