Spring boot – Create a Custom Banner Example
You can change the mission critical banner that is printed on start up with your own custom banner. You have the option to add your own custom banner.txt text file by setting the banner.location
to the location of such a file. The default charset is UTF-8
. In addition you can also add a banner.gif, banner.jpg or banner.png image file or set a banner.image.location
property. Images will be converted into an ASCII art representation and printed above any text banner. In this tutorial we demonstrate how to create a custom banner using spring boot. We Generated an ascii art and place it in a file called banner.txt
and place it in the directory src/main/resources
.
Spring Boot – Custom Banner
In this example we opted for a custom banner.txt
file, which we placed in the src/main/resources
folder. Spring boot’ll automatically use this file.
${Ansi.GREEN} _ __ _
${Ansi.GREEN} /\/\ ___ _ __ ___ ___ _ __ _ _ _ __ ___ | |_ / _| ___ _ _ _ __ __| | ___ ___ _ __ ___
${Ansi.GREEN} / \ / _ \ '_ ` _ \ / _ \| '__| | | | '_ \ / _ \| __| |_ / _ \| | | | '_ \ / _` | / __/ _ \| '_ ` _ \
${Ansi.GREEN} / /\/\ \ __/ | | | | | (_) | | | |_| | | | | (_) | |_| _| (_) | |_| | | | | (_| || (_| (_) | | | | | |
${Ansi.GREEN} \/ \/\___|_| |_| |_|\___/|_| \__, |_| |_|\___/ \__|_| \___/ \__,_|_| |_|\__,_(_)___\___/|_| |_| |_|
${Ansi.GREEN} |___/
${Ansi.RED} :: Spring Boot${spring-boot.formatted-version} :: ${Ansi.DEFAULT}
Tweaking the banner
You can further tweak the banner by adding the following properties to your application.properties
file.
# BANNER
banner.charset=UTF-8 # Banner file encoding.
banner.location=classpath:banner.txt # Banner file location.
banner.image.location=classpath:banner.gif # Banner image file location (jpg/png can also be used).
banner.image.width= # Width of the banner image in chars (default 76)
banner.image.height= # Height of the banner image in chars (default based on image height)
banner.image.margin= # Left hand image margin in chars (default 2)
banner.image.invert= # If images should be inverted for dark terminal themes (default false)
Bootstrap Application
package com.memorynotfound.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
Generated Output
The previous configuration prints the following output to the console.
Nice post.
I think, you forget to prefix the several properties with “spring.”