How To Set Spring Boot Custom Banner


Spring boot custom banner

Spring boot application while starting shows a number of useful information in the console. Generally, the console output will start with a spring boot banner. Like one bellow. In this article we will cover how to change the default banner and turning it on or off etc.
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.6.RELEASE)

How to Turn banner off

We can turn off the banner by configuration changes or by java code change. Following section shows how to turn of the banner in both ways.
application.properties
The banner can be turned off by setting spring.main.banner-mode to off in application.properties file
spring.main.banner-mode=off
The following code demonstrates how we can set the banner mode off though java code in the Main application file.
Main Application Class
@SpringBootApplication
public class HelloApplication implements CommandLineRunner {
  private static final Logger log = LoggerFactory.getLogger(HelloApplication.class);
  public static void main(String[] args) {
    var app = new SpringApplication(HelloApplication.class);
    app.setBannerMode(Banner.Mode.OFF);
    app.run(args);
  }
  @Autowired
  HelloService service;

  @Override
  public void run(String... args) throws Exception {
    log.info(service.hello());
  }
}

Changing the banner

We can change the banner by providing ASCII banner contents in a file and specifying the file location in application.properties.
spring.banner.location points to the banner file. We can also specify additional properties in the banner.txt file. For instance, in the following example, we are specifying application.title, application.version, etc. to be displayed under the banner "bootng"

Code Details

my-banner.txt
ASCII banner content. We are using SpringBoot constants AnsiColor.RED to specify the color of the banner text.
 ${AnsiColor.RED}
 _                    _                 
| |                  | |                
| |__    ___    ___  | |_  _ __    __ _ 
| '_ \  / _ \  / _ \ | __|| '_ \  / _` |
| |_) || (_) || (_) || |_ | | | || (_| |
|_.__/  \___/  \___/  \__||_| |_| \__, |
                                   __/ |
                                  |___/ 
Application Name: ${application.title}
Application Version: ${application.version}  
Spring Boot Version: ${spring-boot.version}
${AnsiColor.DEFAULT}
application.properties
#spring.main.banner-mode=off
spring.banner.location=classpath:my-banner.txt
application.title=Spring Boot Standalone App
application.version=1.0.0

Run The Application

mvn spring-boot:run
Console output
 _                    _
| |                  | |
| |__    ___    ___  | |_  _ __    __ _
| '_ \  / _ \  / _ \ | __|| '_ \  / _` |
| |_) || (_) || (_) || |_ | | | || (_| |
|_.__/  \___/  \___/  \__||_| |_| \__, |
                                   __/ |
                                  |___/

Application Name: Spring Boot Standalone App
Application Version:
Spring Boot Version: 2.2.6.RELEASE

Git Source code

  • git clone https://github.com/siddharthagit/spring-boot-references
  • cd spring-boot-standalone-app
  • mvn clean install
  • mvn spring-boot:run

    5 comments :

    1. very nice explanation

      ReplyDelete
    2. They are timely and treated the entire best web design companies procedure very professionally.

      ReplyDelete
    3. If you should be opting for finest contents like me, just visit this blog site daily because it provides the feature contents, thanks.
      creative web design agency

      ReplyDelete

    Please leave your message queries or suggetions.