Definition of Spring Boot Banner
In Spring boot framework, we have the provision to show our text in the form of a banner when the application starts up. It is the text which shows up when we start our spring boot application, by the use it we can also create the custom banner according to us, but for that, we have to make little changes to our existing application, also if we do not want that banner so we have one option and property in spring boot application to disable it by using the application properties file. It will always get loads when the application starts running, also in the coming section we will see how it looks like, the default text for this banner is ‘spring’ if you try to run your application then at the beginning only you will see one text ‘spring’ get loaded after that the logs starts priming on the screen. In the coming section of the tutorial, we will see how we can implement this to have our own custom banner at the start of the application for better understanding.
As we already know that it is just a banner which shows the text we want at the start of the spring application, let’s take a closer look at what we can do to make it work or not in the existing application see below for a better understanding;
As you can see in the above syntax that we need to set this property into the application.property file to create the custom banner in the spring application. Let’s taken a closer look at the practice syntax which will give us better idea see below;
It should be a class path, in the coming section of the tutorial we will see the full implementation of this banner with the .txt file and where we can keep this file in order to create the banner in the spring boot application.
How Spring boot banner works?
As we already know a banner is a txt file that get loaded when we start our spring boot application and wherever it contains inside it, will get printed on the screen at the start only. banner in spring boot we can say act as the logo here, if you see the default banner of spring boot you will see the ‘Spring’ written as the start. We have so many options in spring-like, either we can disable this logo, or we can relate a custom banner for our application. In the section of the tutorial we will see how we can do all these things but before we will see some basic things for it let’s get started to see below;
1) banner : It is a logo we can say print by the spring framework, which will get print at the start of the application. Spring uses banner.txt file to show this banner, the default name for this file is banner.txt. If we want to create our own custom file with a different name, then we have to follow the below rule which is as follows:
- a) for text to show the file name should end with .txt.
- b) For custom file to show we can add the location of the file into the application property file by using the below syntax
spring. banner.location=classpath:/path: by the use of this we can specify own .txt file with the different name used by the spring, by default it takes banner.txt, but by adding this property it will see and look for this file in the classpath, it should be present in the class path.
2) Default banner: if we talk about the default banner available in the spring boot framework then it ‘Spring’, spring boot taken and loaded this from the banner.txt file, let’s take a closer look at the banner how it looks like in default seating for reference attaching one screenshot for this;
3) Disable : Suppose you do not want any banner to get loaded on the start of the spring boot application then for this also, we can make small changes to the existing application and after that we can try to run our application, steps are mentioned below;
- a) to disable the banner from the spring boot application we have to make an entry inside the application property file.
- b) For this we have to set the banner mode as off in the application file, for reference please follow the below code to make it work;
This property should be set as ‘OFF’ to disable it. Below find the reference attached after making this property as diablo ;
4) Image: We can also add an image as the banner in the spring boot application, but for that, we have to change the file type here. For the image type banner, we have to make banner.png or baner.gif as the file extension. Also after making file we have to follow the below steps to configure it properly;
- a) First we need to create the .gif or .png file place that file in class-path
- b) Second we have to mention the file path inside the application property file like below;
As you notice in the above property we have used ‘image’ property to set the image, but before we have just directly used the banner to set the location of the custom banner file. this thing we have to keep in mind while creating any custom banner in the spring boot application.
- Custom banner example,
- Place the banner inside the resource folder, reference see the screenshot attached;
- Make below changes to application.properties fil;
- Run application you will see the below output:
By the use of it either we can disable the banner or we can add our own banner file to the spring application, this file can be of any type like .txt or .png for the image. This is very easy to crate and handle by the developers so if we want to easily implement it in our application without doing heavy configuration.
This is a guide to Spring Boot Banner. Here we discuss definition, syntax, How Spring boot banner works, examples with code implementation. You may also have a look at the following articles to learn more –