Banner in Spring Boot

Banner in Spring Boot | When we start any Spring Boot application one logo is printed at the console called Banner. This Banner setup and printing is done when we run the starter class.

Banner in Spring Boot

We can even customize our code ie OFF Banner, modify data, etc.

interface Banner {
    enum Mode { OFF, CONSOLE, LOG } ;
}

Example to turn off the Banner (Modify starter class):-

package com.knowprogram.demo;

import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class StopWatchDemoApplication {

    public static void main(String[] args) {
        SpringApplication sa = new SpringApplication(StopWatchDemoApplication.class);
        sa.setBannerMode(Banner.Mode.OFF);
        sa.run(args);
    }

}

Default Banner.Mode.CONSOLE, therefore banner is printed at the console.

Adding Custom Banner in Spring Boot

To provide our own banner file, we need to create one Txt file under the src/main/resources folder because Spring Boot has provided an internal key:- spring.banner.location=classpath:banner.txt

Here, classpath means src/main/resources folder.

You can take the help of any online tool to generate the Spring Boot Banner and download the file. Place the file in the src/main/resources folder. Add the following in the properties file:-

spring.banner.location=classpath:banner.txt

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *