Early adopters of Spring Boot 2.0 - Dynamic Banner

First of all, I declare that it is reproduced from: http://www.ityouknow.com/springboot/2018/03/03/spring-boot-banner.html , thanks to the original author, for infringement and deletion.

Read the table of contents:

1. Configure dependencies

2. Spring Boot replaces the banner

Spring Boot 2.0 provides many new features , one of which is a small easter egg: Dynamic Banner, today we will try this first.

1. Configuration dependencies

To use Spring Boot 2.0, you first need to replace the project dependency package with the just released 2.0 RELEASE, and now the website https://start.spring.io/also sets Spring Boot 2.0 as the default version.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
</parent>

After the setting is complete, dependenciesif there is no version specified in the dependency package, the version that 2.0.0.RELEASE depends on will be used automatically.

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
</dependencies>

Spring Boot 2.0 has just been released, and some Maven repositories have not been updated. If the dependency package cannot be downloaded after importing the project, you can manually add the Spring Boot official Maven repository.

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/libs-milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

Everyone, be mentally prepared. For the first time using Spring Boot 2.0, the complete dependency package needs to be downloaded for about half an hour.

2. Spring Boot replaces Banner

Let's first review how to replace the startup banner in Spring Boot 1.0. In fact, it is very simple. Just create a new file src/main/resourcesunder the path and fill in the string content that needs to be printed.banner.txtbanner.txt

Under normal circumstances, we will use third-party tools to help convert the content, such as the website http://www.network-science.de/ascii/converts text into strings, and the website: http://www.degraeve.com/img2txt.phpimages can be converted into strings.

Let's test with Hello World as the startup string:

.__           .__  .__                               .__       .___
|  |__   ____ |  | |  |   ____   __  _  _____________|  |    __| _/
|  |  \_/ __ \|  | |  |  /  _ \  \ \/ \/ /  _ \_  __ \  |   / __ |
|   Y  \  ___/|  |_|  |_(  <_> )  \     (  <_> )  | \/  |__/ /_/ |
|___|  /\___  >____/____/\____/    \/\_/ \____/|__|  |____/\____ |
     \/     \/                                                  \/

Create a new file under the Spring Boot 2.0 project src/main/resourcespath banner.txt, paste the above string, start the Spring Boot project to observe the startup log, and find that Spring Boot 2.0 has replaced the default Spring string with hello world. Note that Spring Boot 2.0 also supports the method of replacing Banner in 1.0.

Next, test and print the dynamic Banner in the Spring Boot 2.0 project. The gif used is as follows:

Similarly, we put the banner.gif file in the src/main/resourcespath of the project, start the project for testing, and print the information in the output column as follows:

..                                    
                                     .::*                                   
                                      ...                                   
                                                                            
                                                                            
                       
                                                                            



.....                                                             ....      
........                                                            .    ...
........                                                                . ..
......                                                                  ....
....                                                                     ...
.                                                                          .
                                                                            
                                                                            
                                                                            
                                                                            
                                                                            
                                                                            
                                                                            
                                  ..**::**..                                
                                .*::::::::::*.                              
                               .*::::::::::::*.                             
                               .*::::::::::::*.                             
                               .*::::::::::::*.                             
                                .*::::::::::*.                              
                                  ..**::***.                                
                                                                            
                                                                            
                                                                            
                                                                            
                                                                            
                                                                            
                                                                            
..                                                                          
.....                                                                     ..
.....                                                                    ...
......                                                                ......
. ...    .                                                             .....
.       ....                                                             . .



              ............................   .............                  
            .................. .........       ................    .        
        ...................                   ... . ... ............        
     .............   . ...                             ...............      
    .   .........                                         ...........       
       ..........                                            ....... ....   
      ............                                                ........  
      ........                                                     ........
    .... .                                                        .........
   ........                                                        ........
 .........                       ..********..                      ......*..
........                      .**::::::::::::**.                    ........
...........                 .**::::::::::::::::**.                   .......
......                     .*::::::::::::::::::::*.                  .......
... ..                    .*::::::::::::::::::::::*.                 .......
......                    .::::::::::::::::::::::::.                 .......
..........                .::::::::::::::::::::::::.                ... ....
.........                 .*:::::::::::::::::::::::.                    ....
.........                 .*::::::::::::::::::::::*.                     ...
.........                  .*::::::::::::::::::::*.                     ....
 ........                   .**::::::::::::::::**.                 .........
  ... ....                    .**::::::::::::**.                   .........
. ........                        .********..                      .........
   ....... .                                                      ......*..
   .........                                                     .   .....  
    .......                                                    .........    
    ........     .                                          ............    
    ............  ..                                        ...........     
      . .............                                        .........      
       ................                              ....   ..........      
         ............. ....    .                   ......... . ..... .      
          .... ...... .........       . .. .... .............. ....         
            ..       .............  ...........  ..............             


                                                                            
                                                                            
                                                                            
                              ::.        .*:*                               
                           :.        *:*      *. .*:*                       
                        .:*.    *:   .*:*.       :.   .:                    
                    :* :     :.                .::::*    :                  
                  :  :    *         *****.....       *.:   :                
                :   : .:*         .::::::::::**..     ..  : *               
               :   *:           .*:::::::::::::::*.     *   **              
              O *** ...**::::::::::::::::::**. * :.:            
             : .* : .....***::::::::::::::::::::::*. : : O           
             :*. * ..*****::::::::::::::::::::::::*. * : O          
             :   .   .*::::::::::::::::::::::::::::::::*.    ::   *         
            :* : *::::::::::::::::::::::::::::::::::* : O         
           * o *. * :::::::::::::::::::::::::::::::: *. .: o:         
           :  : :   .*::::::::::::::::::::::::::::::::::*.   :  . :         
           :  ..    .*::::::::::::::::::::::::::::::::::*.   *  : *         
           :   :    .*::::::::::::::::::::::::::::::::::*   :   *:          
           . :* .*O:::::::::::::::::::::::::::::::*. . :           
            :  :  *   .*::::::::::::::::::::::::::::::*.   *   :*           
             O * : .*::::::::::::::::::::::::::::*. : ** :           
               :*   *    .*::::::::::::::::::::::::**.    *..  *            
                **   *    ..*::::::::::::::::::::*..     :*   *             
                 * O .. ..**::::::::::::**.. .:. : :              
                  : O.: ...******... *. : :.               
                    : ::O:. *: * *:                  
                      :.    :       .*:*.   :*    .*::                      
                         .:* .* *O: .:                         
                                 .:*.        .*:                                          
               
      

      ...

Through the above output, we found that when Spring Boot starts, it will print each picture of the gif image in the log in order. After all the pictures are printed, the Spring Boot project will be started.

If the directory src/main/resourcesexists at the same time banner.txt, banner.gifthe project will banner.gifprint each screen first, and then print banner.txtthe content.

What is the use of the project startup Banner? In some large organizations or companies, you can use this feature to customize your own startup screen to increase the team's sense of brand identity.

Sample Code - Code Cloud

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325049010&siteId=291194637