How to change Spring Boot default Banner

You should have noticed that when you run a Spring Boot application a banner is displayed at the beginning of the application. For your own purposes, you can customize the starting banner by implementing the org.springframework.boot.Banner interface. Let’s see an example of it:

package com.demo;

import java.io.PrintStream;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

@SpringBootApplication
public class SpringBootSimpleApplication {
  public static void main(String[] args) {
    SpringApplication app = new SpringApplication(SpringBootSimpleApplication.class);
    app.setBanner(
        new Banner() {
          @Override
          public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
            out.print("nntWelcome to my CUSTOM Banner!nn".toUpperCase());
          }
        });
    app.run(args);
  }
}

When you run the application, you will see something like this:

$ ./mvnw spring-boot:run
Welcome to my CUSTOM Banner!

Found the article helpful? if so please follow us on Socials
Twitter Icon       Facebook Icon       LinkedIn Icon       Mastodon Icon