Learnitweb

Disable banner in Spring boot

1. Introduction

When Spring Boot application is started, a banner is printed. The banner looks like the following:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.0)

Sometimes you may want to customize this banner. For example, if you want to show the name of your application or product at application startup, you can choose to customize the banner. You can also choose not to show this banner at all. In this tutorial, we’ll discuss ways to disable this banner.

2. Using spring.main.banner-mode property

You can use spring.main.banner-mode property in application.properties to disable banner. The benefit of using configuration is that it requires no code change.

spring.main.banner-mode=off

If you are using application.yml:

spring:
    main:
        banner-mode: "off"

3. Disable banner programmatically

You can disable banner in Spring Boot programmatically as well. The disadvantage of using this approach is that code change is required.

If you are using SpringApplicationBuilder, you can set the banner off like the following:

new SpringApplicationBuilder(MyApplication.class)
.bannerMode(Banner.Mode.OFF)
.run(args);

If you are using SpringApplication, you can set the banner off like the following:

SpringApplication app = new SpringApplication(LazyInitializationDemoApplication.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);

4. Using empty banner.txt

You can customize the banner by creating banner.txt file in the classpath. If the banner.txt file is empty, nothing will be printed on the console. You can specify the location of the banner.txt as well like the following:

spring.banner.location=classpath:/banner.txt

The only thing to do while using banner.txt is create an empty banner.txt.

5. Conclusion

In this tutorial, we discussed how to disable banner using configuration and programmatically.