How to create a custom starting banner for Spring Boot?

January 04, 2020 No comments Custom Banner Spring Boot

1. Introduction

In this article, you will learn how to configure a custom Spring Boot starting banner.

2. Customizing the Spring Boot banner

Spring Boot provides a convenient way to change its banner, the one that is printed on the start up of the application. Default Spring Boot banner looks similar to the following:

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

To change that output you have to place special banner.txt file into the classpath. In Maven projects you have to create a banner file in your /resources folder.

Structure of this file is not formalized, you can put any ASCII character there. Additionally Spring Boot provides several placeholders you can use inside banner.txt file, that will be replaced with specific values:

  • ${application.version} - the version number of your application, as declared in MANIFEST.MF, ex. 2.1.5.RELEASE (note that if you don't have MANIFEST.MF file this value will be empty),
  • ${application.formatted-version} - version of the application formatted for display, ex. (v2.1.5.RELEASE),
  • ${spring-boot.version} - version of the Spring Boot you are using in current project,
  • ${spring-boot.formatted-version} - formated version of Spring Boot,
  • ${application.title} - title of your application, as declared in MANIFEST.MF (note that if you don't have MANIFEST.MF file this value will be empty).

For example filling banner.txt file with the following content:

  _____                _   ____             _    _____           _
 |  ___| __ ___  _ __ | |_| __ )  __ _  ___| | _| ____|_ __   __| |
 | |_ | '__/ _ \| '_ \| __|  _ \ / _` |/ __| |/ /  _| | '_ \ / _` |
 |  _|| | | (_) | | | | |_| |_) | (_| | (__|   <| |___| | | | (_| |
 |_|  |_|  \___/|_| |_|\__|____/ \__,_|\___|_|\_\_____|_| |_|\__,_|
 ${spring-boot.version} ----------------------------------------------------

will produce the following output on Spring Boot start up console:

  _____                _   ____             _    _____           _
 |  ___| __ ___  _ __ | |_| __ )  __ _  ___| | _| ____|_ __   __| |
 | |_ | '__/ _ \| '_ \| __|  _ \ / _` |/ __| |/ /  _| | '_ \ / _` |
 |  _|| | | (_) | | | | |_| |_) | (_| | (__|   <| |___| | | | (_| |
 |_|  |_|  \___/|_| |_|\__|____/ \__,_|\___|_|\_\_____|_| |_|\__,_|
 2.1.5.RELEASE ----------------------------------------------------

2019-06-15 23:23:49.397  INFO 8398 --- [           main] com.frontbackend.Application             : Starting Application on dell with PID 8398 (/home/frontbackend/projects/tutorials/spring-boot/custom-banner/target/classes started by frontbackend in /home/frontbackend/projects/tutorials)
2019-06-15 23:23:49.400  INFO 8398 --- [           main] com.frontbackend.Application             : No active profile set, falling back to default profiles: default
2019-06-15 23:23:50.285  INFO 8398 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-06-15 23:23:50.301  INFO 8398 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-06-15 23:23:50.302  INFO 8398 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.19]
2019-06-15 23:23:50.353  INFO 8398 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-06-15 23:23:50.353  INFO 8398 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 914 ms
2019-06-15 23:23:50.490  INFO 8398 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-06-15 23:23:50.618  INFO 8398 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-06-15 23:23:50.621  INFO 8398 --- [           main] com.frontbackend.Application             : Started Application in 1.542 seconds (JVM running for 2.045)

If you want to create similar fancy banner text, using ASCI codes only, go here.

3. Turning off banner

Spring Boot gives you the ability to turn off the banner completely, so it wouldn't be displayed anywhere on start up.

1) you can use spring.main.banner-mode property in configuration file to determine if the banner has to be printed:

YAML file:

spring:
    main:
        banner-mode: "off"

Properties file:

spring.main.banner-mode: "off"

, or

2) set bannerMode parameter which is available on SpringApplication object:

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

{{ 'Comments are closed.' | trans }}