Spring Boot – Custom Banner
Setting Spring Boot Custom Banner
What is Banner?
Banner can be a plain text or image that is displayed while starting up any spring boot application, which would be something like below by default.
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.1.6.RELEASE)
How to Customize Spring boot Banner?
In order to set any custom spring boot banner banner.txt
file placed in src/main/resources
directory and paste the customized banner content into it. For example, I have created a customized banner for TalksInfo as below.
_ __ __ _ ___ / |_ [ | [ | _ (_) .' ..] `| |-' ,--. | | | | / ] .--. __ _ .--. _| |_ .--. | | `'_\ : | | | '' < ( (`\] [ | [ `.-. | '-| |-' / .'`\ \ | |, // | |, | | | |`\ \ `'.'. | | | | | | | | | \__. | \__/ \'-;__/ [___] [__| \_] [\__) ) [___] [___||__] [___] '.__.'
Inside your banner.txt
file, you can use any of the following placeholders.
Also banner.txt is the default expected banner file name, which Spring Boot uses. However, if we want to choose any other location or another name for the banner, we need to set the spring.banner.location property in the application.properties file.
We can also use images as banners too. Same as with banner.txt, Spring Boot expects the banner image’s name as banner.gif. Additionally, we can set different image properties such as height, width, etc. in the application.properties:
spring.banner.image.location=classpath:banner.gif spring.banner.image.width= //TODO spring.banner.image.height= //TODO spring.banner.image.margin= //TODO spring.banner.image.invert= //TODO
You can also use the spring.main.banner-mode
property to determine if the banner has to be printed on System.out
(console
), sent to the configured logger (log
), or not produced at all (off
).
The printed banner is registered as a singleton bean under the following name: springBootBanner
.
Conclusion
Hence we saw what is banner, how to setup custom banner in Spring Boot and some properties which accompanies while setting it up.