Using Custom Banners in Spring Boot

1. Overview

By default, Spring Boot comes with a banner which shows up as soon as the application starts.

In this article, we’ll learn how to create a custom banner and use it in Spring Boot applications.

2. Creating a Banner

Before we start, we need to create the custom banner which will be displayed at the time of application start-up time. We can create the custom banner from scratch or use various tools that will do this for us.

In this example we used VietMX’s official logo:

 __  __       ___   __             __      ___      _     _____                
|  \/  |     (_) \ / /             \ \    / (_)    | |   / ____|               
| \  / | __ _ _ \ V /_   _  __ _ _ _\ \  / / _  ___| |_ | |     ___  _ __ ___  
| |\/| |/ _` | | > <| | | |/ _` | '_ \ \/ / | |/ _ \ __|| |    / _ \| '_ ` _ \ 
| |  | | (_| | |/ . \ |_| | (_| | | | \  /  | |  __/ |_ | |___| (_) | | | | | |
|_|  |_|\__,_|_/_/ \_\__,_|\__,_|_| |_|\/   |_|\___|\__(_)_____\___/|_| |_| |_|
                                                                               
 _____   _      ______      ________  __      _______ ______ _______ __  ____   __
|_   _| | |    / __ \ \    / /  ____| \ \    / /_   _|  ____|__   __|  \/  \ \ / /
  | |   | |   | |  | \ \  / /| |__     \ \  / /  | | | |__     | |  | \  / |\ V / 
  | |   | |   | |  | |\ \/ / |  __|     \ \/ /   | | |  __|    | |  | |\/| | > <  
 _| |_  | |___| |__| | \  /  | |____     \  /   _| |_| |____   | |  | |  | |/ . \ 
|_____| |______\____/   \/   |______|     \/   |_____|______|  |_|  |_|  |_/_/ \_\
                                                                                  

However, in some situation, we might like to use the banner in the plain text format since it’s relatively easier to maintain.

The plain-text custom banner which we used in this example is available here.

Point to note here is that ANSI charset has the ability to display colorful text in the console. This can’t be done with the simple plain text format.

3. Using the Custom Banner

Since we have the custom banner ready, we need to create a file named banner.txt in the src/main/resources directory and paste the banner content into it.

Point to note here is that 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:

spring.banner.location=classpath:/path/to/banner/bannername.txt

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

However, it’s always better to use text format because the application start up time will drastically increase if some complex image structure is used.

4. Conclusion

In this quick article, we showed how to use a custom banner in Spring Boot applications.

Like always, the full source code is available over on GitHub.

Related posts:

Hướng dẫn tạo và sử dụng ThreadPool trong Java
Intro to Inversion of Control and Dependency Injection with Spring
Sử dụng Fork/Join Framework với ForkJoinPool trong Java
The Guide to RestTemplate
Spring Boot - Bootstrapping
Comparing Two HashMaps in Java
Auditing with JPA, Hibernate, and Spring Data JPA
Java Program to Represent Graph Using 2D Arrays
Arrays.asList vs new ArrayList(Arrays.asList())
Java Program to Repeatedly Search the Same Text (such as Bible by building a Data Structure)
Java Program to Implement Interpolation Search Algorithm
Java Program to Find Inverse of a Matrix
Java Program to Implement Traveling Salesman Problem using Nearest neighbour Algorithm
Spring Security Custom AuthenticationFailureHandler
Spring Cloud AWS – EC2
Java Program to Implement Skew Heap
Java Program to Implement String Matching Using Vectors
Java Program to Generate a Random UnDirected Graph for a Given Number of Edges
Spring Security Logout
Java Program to Implement Fenwick Tree
Hướng dẫn sử dụng Printing Service trong Java
Ép kiểu trong Java (Type casting)
A Guide to EnumMap
Hướng dẫn Java Design Pattern – Chain of Responsibility
Java Program to Generate a Random Subset by Coin Flipping
Java Program to Generate All Possible Combinations of a Given List of Numbers
Java Multi-line String
Giới thiệu Json Web Token (JWT)
The Registration API becomes RESTful
Java Program to Solve a Matching Problem for a Given Specific Case
Registration – Activate a New Account by Email
Java Program to Implement Dijkstra’s Algorithm using Priority Queue