How to use Spring Boot to customize banner - Alan Lee, case details

When the Spring Boot project starts, the following will be printed.

1   .   ____          _            __ _ _
2  /\ / ___"_ __ _ _(_)_ __  __ _    
3 ( ( )\___ | "_ | "_| | "_ / _` |    
4  \/  ___)| |_)| | | | | || (_| |  ) ) ) )
5   "  |____| .__|_| |_|_| |_\__, | / / / /
6  =========|_|==============|___/=/_/_/_/
7  :: Spring Boot ::        (v2.1.4.RELEASE)

Note: light theory is not enough. By the way, I'll send you ten sets of practical tutorials and interview question bank of the latest JAVA architecture project in 2020, which can be found under the transformation of seven bar umbrella bar and Zero clothing umbrella (Digital homophony), and also can communicate with the old architect

How can we customize the printed content?

Customizing Banner is very simple. You only need to create a file named banner.txt under classpath (src/main/resources), and then write what you want to print in banner.txt.

For example:

 1                     _ooOoo_
 2                    o8888888o
 3                    88" . "88
 4                    (| ^_^ |)
 5                    O  =  /O
 6                 ____/`---"\____
 7               ."  \|     |//  `.
 8              /  \|||  :  |||//  
 9             /  _||||| -:- |||||-  
10             |   | \  -  /// |   |
11             | \_|  ""---/""  |   |
12               .-\__  `-`  ___/-. /
13           ___`. ."  /--.--  `. . ___
14         ."" "<  `.___\_<|>_/___."  >""".
15       | | :  `- `.;` _ /`;.`/ - ` : | |
16 ========`-.____`-.___\_____/___.-`____.-"========
17          `-.   \_ __ /__ _/   .-` /  /
18                      `=---="
19 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20          Buddha bless       Never down       Never Bug

 

How to print project related information?

banner.txt supports placeholders, which can be used to describe projects and customize the details of banner display.

The allowed placeholders are shown in the following table:

Variable Description
${application.version} Application version, read the implementation version value from MANIFEST.MF and display it. For example, if implementation version: 1.0, print 1.0
${application.formatted-version} Enclose the application version in brackets and add the prefix v. For example: implementation version: 1.0, print (v1.0)
${spring-boot.version} Print the Spring Boot version, for example, 2.1.4.RELEASE
${spring-boot.formatted-version} Enclose the Spring Boot version in parentheses and add the prefix v. For example: (v2.1.4.RELEASE)
${Ansi.NAME} (or ${AnsiColor.NAME}, ${AnsiBackground.NAME}, ${AnsiStyle.NAME}) Specify the ANSI escape code. See org.springframework.boot.ansi.AnsiPropertySource for details
${application.title} Apply the title, read the value of implementation title from MANIFEST.MF and print it. For example, implementation Title: itsuch app, the itsuch app will be printed.

For example:

 1 ${AnsiColor.GREEN}
 2                     _ooOoo_
 3                    o8888888o
 4                    88" . "88
 5                    (| ^_^ |)
 6                    O  =  /O
 7                 ____/`---"\____
 8               ."  \|     |//  `.
 9              /  \|||  :  |||//  
10             /  _||||| -:- |||||-  
11             |   | \  -  /// |   |
12             | \_|  ""---/""  |   |
13               .-\__  `-`  ___/-. /
14           ___`. ."  /--.--  `. . ___
15         ."" "<  `.___\_<|>_/___."  >""".
16       | | :  `- `.;` _ /`;.`/ - ` : | |
17 ========`-.____`-.___\_____/___.-`____.-"========
18          `-.   \_ __ /__ _/   .-` /  /
19                      `=---="
20 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21          Buddha bless       Never down       Never Bug
22 ==================================================
23 Application Info: ${application.title}-${application.version}
24 Powered by: Spring Boot ${spring-boot.version}

 

How to disable Banner?

Add the following configuration:

1 spring:
2   main:
3     banner-mode: "off"

Or add the following code on the startup class:

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

 

Attach the Banner I used:

======Powered by: Spring Boot ${spring-boot.version}======
                    _ooOoo_
                   o8888888o
                   88" . "88
                   (| ^_^ |)
                   O  =  /O
                ____/`---"\____
              ."  \|     |//  `.
             /  \|||  :  |||//  
            /  _||||| -:- |||||-  
            |   | \  -  /// |   |
            | \_|  ""---/""  |   |
              .-\__  `-`  ___/-. /
          ___`. ."  /--.--  `. . ___
        ."" "<  `.___\_<|>_/___."  >""".
      | | :  `- `.;` _ /`;.`/ - ` : | |
========`-.____`-.___\_____/___.-`____.-"========
         `-.   \_ __ /__ _/   .-` /  /
                     `=---="
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      //Buddha bless never down, never Bug

Do you understand? Last note: by the way, I'll send you ten sets of practical courses and interview question bank of the latest JAVA architecture project in 2020, which can be put into my skirt: seven bar umbrella bar zero and clothes zero umbrella (Digital homophony) can be found under the conversion, and can also communicate with the old architect

The text and pictures of this article come from the Internet and my own ideas. They are only for learning and communication. They have no commercial use. The copyright belongs to the original author. If you have any questions, please contact us in time for handling

Tags: Java Spring

Posted on Mon, 18 May 2020 10:36:46 -0400 by jds580s