1. Introduction
Whenever Spring Boot application is started, a banner is printed. The banner looks like the following:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.6.0)
This startup banner can be customized. We can use custom text as well as image.
2. How to customize banner in Spring Boot?
There are two ways to change the banner:
- Adding
banner.txt
file in classpath. In Spring Boot project,banner.txt file
can be placed insrc/main/resources
. The filebanner.txt
contains the banner to be displayed. - Setting
spring.banner.location
property to the location of banner file.
3. Using image as a banner
An image file can also be used as a banner by following two ways:
- Adding a
banner.gif
,banner.jpg
, orbanner.png
image file to your classpath. In Spring Boot project, image file can be placed insrc/main/resources
. The filebanner.txt
contains the banner to be displayed. - Setting
spring.banner.image.location
property to the location of the banner image.
4. Placeholders in banner.txt
The banner.txt
file can contain certain placeholders. These placeholders represent specific information which you may want to print.
${application.version} | The version number of your application, as declared in MANIFEST.MF. |
${application.formatted-version} | The version number of your application, as declared in MANIFEST.MF. The value is formatted for display, enclosed within brackets and prefixed with v. For example (v2.1). |
${spring-boot.version} | The Spring Boot version. |
${spring-boot.formatted-version} | The Spring Boot version, formatted for display, enclosed within brackets and prefixed with v. For example, (2.6.1). |
${Ansi.NAME} (or ${AnsiColor.NAME}, ${AnsiBackground.NAME}, ${AnsiStyle.NAME}) | Here, NAME is the name of ANSI escape code. For example, ${Ansi.RED}. |
${application.title} | Application title as specified in MANIFEST.MF. |
5. Example of custom banner in Spring Boot
Create banner.txt
file having following content and place in resources
folder of your Spring Boot application.
${Ansi.BLUE}========================================
${Ansi.RED} This is custom banner
${Ansi.BLUE}========================================
${Ansi.GREEN} Spring Boot version: ${spring-boot.version}
${Ansi.GREEN} Spring Boot formatted version: ${spring-boot.formatted-version}
${Ansi.BLUE}========================================
When the application is started the output would look like the following:
6. Other properties for banner
There are few other properties related to banner.
Name | Description | Default Value |
spring.banner.charset | Banner file encoding | UTF-8 |
spring.banner.image.bitdepth | Bit depth to use for ANSI colors. Supported values are 4 or 8. | 4 |
spring.banner.image.height | Height of the banner image in chars | |
spring.banner.image.invert | Whether images should be inverted for dark terminal themes. | false |
spring.banner.image.margin | Left hand image margin in chars. | 2 |
spring.banner.image.pixelmode | Pixel mode to use when rendering the image. | TEXT |
spring.banner.image.width | Width of the banner image in chars. | 76 |
7. Conclusion
In this tutorial, we discussed how to customize banner in Spring Boot and how to use placeholders in banner. The custom banner is used when you want to show your product information when you ship your product.