Spring Boot Customize Banner

0

By default spring boot looks out for banner.txt and banner(.jpg/.png/.gif) image. If it finds one and then it goes ahead to use it for the banner.

BannerExampleApplication:

package com.javarticles.springboot.banner.bannerExample;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class BannerExampleApplication {

	public static void main(String[] args) {
		SpringApplication.run(BannerExampleApplication.class, args);
	}
}


Output:

 :::::::::::::::::::::*::::::**************::*:*******:**********************
  ::::::::::::::::::::::::*:********::***:::o#8888&8&o************************
  ::::::::::::::::::::*:*...::&&o:::o::o&888&oooo&oooo&88:***::***************
  ::::::::::::::::::::*..o&&o:oo&&&&##&&8:&&&&&8&&&&&&&&88&*************:*****
  :::::::::::::::::::**&&&::oooo&&&888#ooooo&&&&&&&&&&&&&&&8******************
  :::::::::::::::::.o&&:::ooooooo&&&8#8oooooooooo&&&&&&oo&oo&o****************
  ::::::::::::::::*:&&:::oooo:::oooo&&8ooooooooo&&8888&&&&oo&8&:**************
  :::::::::::::::*o&&&::oooo:::::::::oo&ooooooo&#####888&ooo:8&::*************
  ::::::::::::::*o&o:::::ooo::*:::::::o&oo:oooo#@@@@@@#88&ooo&8o:*************
  :::::::::::::::&o::::::o&88888o:::**:[email protected]@@@@#@#88&&ooo8&o::***********
  :::::::::::::::&o:*::o&&8#@@@@#&:****o&&oooo&@@@@@@@88&&o&oo&8&o::**:*:*****
  :::::::::::::::o:*:::&&[email protected]@&@@@@#8*..*oo8ooooo#@@@@#88&&&&&&&&8&ooo:**:******
  ::::::::::::::*&:***:o&&#@#@@@@@8o**.*o8&o&ooo#88&&&&&&&&&&88&ooo::::*******
  ::::::::::::::*:o.***::&&&@@@@@#8:**.**8&&&&&&88&&&&&o&&&o8#&&oooo:::::*****
  :::::::::::::::******:::oooooo:ooo:**::o8&&&͸&&&&oo&&8#&&&&&&oo::o:::*:*
  :::::::::::::::*.:*.*****::::**:ooo::::&888&8##888&&&&&&8##888&&&&&&oooo:*::
  ::::::::::::::::* o:********.*:ooo&8&ooo&8888##88&&&&&&[email protected]#888&&&&888&8&ooo::
  :::::::::::::::::.*&o***::*****::o&&8o&&:*o####88&&&&&&##88888&8&&&&&&&&ooo*
  :::::::::::::::::*..8&**:::******:oo&8&:*.:&&888&&&&&[email protected]#888##8888&8&&o&&o&:
  ::::::::::::::::::*..:&&***********:o&8&**:o&88&&&&&8#@#888####88888888&&&&&
  :::::::::::::::::::*.. o&&*********::o&88::o&8&&&&8#@##8888##88#8888888&&88o
  ::::::::::::::::::::....*o&o::******:oo&&8*o&&&&&[email protected]@8888#8#######88888888888
  :::::::::::::::::::::**... o8&:oooo::oo:oo&:o&&8#888888#######8888888#888#8#
  ::::::::::::::::::::::**.*....::*ooo8#8#888&&8888888###8####888888888#8888#8
  :::::::::::::::::::::::***....**:::o&o&&&&&8888888888######8䰫�&8#8
  :::::::::::::::::::::::***..**.:::o&ooo&8888###88#########8#####88888##&8888
  :::::::::::::::::::::::::*.****:*ooo&&&&88##@@#8##88#88888############88888&
  ::::::::::::::::::::::::::..****::&&&&&888###&8888888&&&8&8##888######88&&8&
  ::::::::::::::::::::::::::****:*:oo&&888###8&8&88&&&8888888888888######888&o
  :::::::::::::::::::::::::::*****:o&&8888##88&&&&&&&88888&o#8888&######888&&o
  ::::::::::::::::::::::::::::****:oo&&###&&&&&&o&8&&&&888o&888888##8###88&&&&
  :::::::::::::::::::::::::::::****ooo8##8&&&oo&&&&⊸&&&8888##8####88o&&8&
  ::[email protected]::::::::::::::::::::::::::*..o:&8##&oo&o&o&&&:888&&8&88#############8888
  :::::::::::::::::::::::::::::::**:oo8#8ooooo&o&&&&&&&&8#88####88#88######888
  :::::::::::::::::::::::::::::::**o8888&oooooooo&&&&&&&o8888888888#########&8

_________ _______           _______  _______ __________________ _______  _        _______  _______ 
\__    _/(  ___  )|\     /|(  ___  )(  ____ )\__   __/\__   __/(  ____ \( \      (  ____ \(  ____ \
   )  (  | (   ) || )   ( || (   ) || (    )|   ) (      ) (   | (    \/| (      | (    \/| (    \/
   |  |  | (___) || |   | || (___) || (____)|   | |      | |   | |      | |      | (__    | (_____ 
   |  |  |  ___  |( (   ) )|  ___  ||     __)   | |      | |   | |      | |      |  __)   (_____  )
   |  |  | (   ) | \ \_/ / | (   ) || (\ (      | |      | |   | |      | |      | (            ) |
|\_)  )  | )   ( |  \   /  | )   ( || ) \ \__   | |   ___) (___| (____/\| (____/\| (____/\/\____) |
(____/   |/     \|   \_/   |/     \||/   \__/   )_(   \_______/(_______/(_______/(_______/\_______)

You can also provide your own banner file location set against system property spring.banner.location. The banner image file location is set against system property spring.banner.image.location.

CustomBannerFileExampleApplication:

package com.javarticles.springboot.banner.bannerExample;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CustomBannerFileExampleApplication {

	public static void main(String[] args) {
		System.setProperty("spring.banner.location", "banner/customBanner.txt");
		SpringApplication.run(CustomBannerFileExampleApplication.class, args);
	}
}

Output:

  :::::::::::::::::::::*::::::**************::*:*******:**********************
  ::::::::::::::::::::::::*:********::***:::o#8888&8&o************************
  ::::::::::::::::::::*:*...::&&o:::o::o&888&oooo&oooo&88:***::***************
  ::::::::::::::::::::*..o&&o:oo&&&&##&&8:&&&&&8&&&&&&&&88&*************:*****
  :::::::::::::::::::**&&&::oooo&&&888#ooooo&&&&&&&&&&&&&&&8******************
  :::::::::::::::::.o&&:::ooooooo&&&8#8oooooooooo&&&&&&oo&oo&o****************
  ::::::::::::::::*:&&:::oooo:::oooo&&8ooooooooo&&8888&&&&oo&8&:**************
  :::::::::::::::*o&&&::oooo:::::::::oo&ooooooo&#####888&ooo:8&::*************
  ::::::::::::::*o&o:::::ooo::*:::::::o&oo:oooo#@@@@@@#88&ooo&8o:*************
  :::::::::::::::&o::::::o&88888o:::**:[email protected]@@@@#@#88&&ooo8&o::***********
  :::::::::::::::&o:*::o&&8#@@@@#&:****o&&oooo&@@@@@@@88&&o&oo&8&o::**:*:*****
  :::::::::::::::o:*:::&&[email protected]@&@@@@#8*..*oo8ooooo#@@@@#88&&&&&&&&8&ooo:**:******
  ::::::::::::::*&:***:o&&#@#@@@@@8o**.*o8&o&ooo#88&&&&&&&&&&88&ooo::::*******
  ::::::::::::::*:o.***::&&&@@@@@#8:**.**8&&&&&&88&&&&&o&&&o8#&&oooo:::::*****
  :::::::::::::::******:::oooooo:ooo:**::o8&&&͸&&&&oo&&8#&&&&&&oo::o:::*:*
  :::::::::::::::*.:*.*****::::**:ooo::::&888&8##888&&&&&&8##888&&&&&&oooo:*::
  ::::::::::::::::* o:********.*:ooo&8&ooo&8888##88&&&&&&[email protected]#888&&&&888&8&ooo::
  :::::::::::::::::.*&o***::*****::o&&8o&&:*o####88&&&&&&##88888&8&&&&&&&&ooo*
  :::::::::::::::::*..8&**:::******:oo&8&:*.:&&888&&&&&[email protected]#888##8888&8&&o&&o&:
  ::::::::::::::::::*..:&&***********:o&8&**:o&88&&&&&8#@#888####88888888&&&&&
  :::::::::::::::::::*.. o&&*********::o&88::o&8&&&&8#@##8888##88#8888888&&88o
  ::::::::::::::::::::....*o&o::******:oo&&8*o&&&&&[email protected]@8888#8#######88888888888
  :::::::::::::::::::::**... o8&:oooo::oo:oo&:o&&8#888888#######8888888#888#8#
  ::::::::::::::::::::::**.*....::*ooo8#8#888&&8888888###8####888888888#8888#8
  :::::::::::::::::::::::***....**:::o&o&&&&&8888888888######8䰫�&8#8
  :::::::::::::::::::::::***..**.:::o&ooo&8888###88#########8#####88888##&8888
  :::::::::::::::::::::::::*.****:*ooo&&&&88##@@#8##88#88888############88888&
  ::::::::::::::::::::::::::..****::&&&&&888###&8888888&&&8&8##888######88&&8&
  ::::::::::::::::::::::::::****:*:oo&&888###8&8&88&&&8888888888888######888&o
  :::::::::::::::::::::::::::*****:o&&8888##88&&&&&&&88888&o#8888&######888&&o
  ::::::::::::::::::::::::::::****:oo&&###&&&&&&o&8&&&&888o&888888##8###88&&&&
  :::::::::::::::::::::::::::::****ooo8##8&&&oo&&&&⊸&&&8888##8####88o&&8&
  ::[email protected]::::::::::::::::::::::::::*..o:&8##&oo&o&o&&&:888&&8&88#############8888
  :::::::::::::::::::::::::::::::**:oo8#8ooooo&o&&&&&&&&8#88####88#88######888
  :::::::::::::::::::::::::::::::**o8888&oooooooo&&&&&&&o8888888888#########&8

 _______           _______ _________ _______  _______    ______   _______  _        _        _______  _______
(  ____ \|\     /|(  ____ \\__   __/(  ___  )(       )  (  ___ \ (  ___  )( (    /|( (    /|(  ____ \(  ____ )
| (    \/| )   ( || (    \/   ) (   | (   ) || () () |  | (   ) )| (   ) ||  \  ( ||  \  ( || (    \/| (    )|
| |      | |   | || (_____    | |   | |   | || || || |  | (__/ / | (___) ||   \ | ||   \ | || (__    | (____)|
| |      | |   | |(_____  )   | |   | |   | || |(_)| |  |  __ (  |  ___  || (\ \) || (\ \) ||  __)   |     __)
| |      | |   | |      ) |   | |   | |   | || |   | |  | (  \ \ | (   ) || | \   || | \   || (      | (\ (
| (____/\| (___) |/\____) |   | |   | (___) || )   ( |  | )___) )| )   ( || )  \  || )  \  || (____/\| ) \ \__
(_______/(_______)\_______)   )_(   (_______)|/     \|  |/ \___/ |/     \||/    )_)|/    )_)(_______/|/   \__/

The banner bean can be retrieved using bean ID “springBootBanner”. One can reprint the banner again.

BannerBeanExampleApplication:

package com.javarticles.springboot.banner.bannerExample;

import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class BannerBeanExampleApplication {

	public static void main(String[] args) {
		ApplicationContext context = SpringApplication.run(BannerBeanExampleApplication.class, args);
		((Banner)context.getBean("springBootBanner")).printBanner(context.getEnvironment(), null, System.out);
	}
}

In the below example we set a custom implementation of Banner. You can use the custom implementation to append other information that you may need to fetch from some external resource. For example, the application version etc.

CustomBannerApplication:

package com.javarticles.springboot.banner.bannerExample;

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

import java.io.PrintStream;

@SpringBootApplication
public class CustomBannerApplication {
    //move banner* files to some other folder for this to work
    public static void main(String[] args) {
        SpringApplication sa = new SpringApplication(CustomBannerApplication.class);
        sa.setBanner(new Banner() {
            @Override
            public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
                out.println("My own Banner implementation....");
            }
        });
        sa.run(args);
    }
}

Output:

My own Banner implementation....

Download the source code

This was an example about the different ways of customizing spring boot banner.

You can download the source code here: springBootBannerExample.zip
Share.

Comments are closed.