Spring Boot – Startup Banner Configuration

Learn to disable the default start-up banner in a Spring Boot application. By default, the banner prints string Spring Boot along with its version information.

Spring boot banner
Default banner printed on application startup

1. Banner Modes

The banner can be configured in three modes:

Banner Mode Description
LOG Print banner only in log files
CONSOLE Print banner only in console
OFF Do not print the banner anywhere

2. Properties Based Configuration

If we do not want to change the application code for disabling or changing the startup banner mode, we can pass the property spring.main.banner-mode as runtime argument. This is the recommended approach.

[java title=”Console”]
$ java -Dspring.main.banner-mode=off -jar application.jar
[/java]

If we can change the sourcecode of the application then we can set the banner mode in resources/application.properties file.

[java title=”application.properties”]
spring.main.banner-mode=off
[/java]

Or, if we are using the resources/applicaion.yaml.

[java title=”application.yaml”]
spring:
main:
banner-mode:"off"
[/java]

3. Setting Banner.Mode in SpringApplication

In this approach, we need to modify the sourcecode of the application so it is not recommended.

We can set the Banner.Mode in SpringApplcation in two ways. Lets look at the example of both ways.

  • SpringApplication.setBannerMode()

    [java title=”Application.java” highlight=”10″]
    import org.springframework.boot.Banner;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;

    @SpringBootApplication
    public class Application {
    public static void main(String[] args)
    {
    SpringApplication app = new SpringApplication(Application.class);
    app.setBannerMode(Banner.Mode.OFF);
    app.run(args);
    }
    }
    [/java]

  • SpringApplicationBuilder.bannerMode()

    [java title=”Application.java” highlight=”10″]
    import org.springframework.boot.Banner;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;

    @SpringBootApplication
    public class Application {

    public static void main(final String[] args) {
    new SpringApplicationBuilder(Application.class)
    .bannerMode(Banner.Mode.OFF)
    .run(args);
    }
    }
    [/java]

Happy Learning !!

Leave a Comment