springboot banner彩蛋

147 阅读1分钟

这是我参与8月更文挑战的第5天,活动详情查看:8月更文挑战

🙈还是在上家公司,写的这篇博客,今天来更新一下。

先贴一下依赖:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.4</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

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

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

可以看到使用的是目前最新版本的springboot,依赖只需要一个web,能启动容器即可。

banner的创建并不复杂,只需要在/src/main/resources目录下创建一个banner.txt文件即可。

这是一些常用的生成ASCII字符的网站,可以在里面挑选一些,可以写项目名称之类的:

简单尝鲜的话,可以复制下面这个。

${AnsiColor.BRIGHT_YELLOW}
////////////////////////////////////////////////////////////////////
//                          _ooOoo_                               //
//                         o8888888o                              //
//                         88" . "88                              //
//                         (| ^_^ |)                              //
//                         O\  =  /O                              //
//                      ____/`---'____                           //
//                    .'  \|     |//  `.                         //
//                   /  \|||  :  |||//  \                        //
//                  /  _||||| -:- |||||-  \                       //
//                  |   | \\  -  /// |   |                       //
//                  | _|  ''---/''  |   |                       //
//                  \  .-__  `-`  ___/-. /                       //
//                ___`. .'  /--.--\  `. . ___                     //
//              ."" '<  `.____<|>_/___.'  >'"".                  //
//            | | :  `- `.;`\ _ /`;.`/ - ` : | |                 //
//            \  \ `-.   _ __\ /__ _/   .-` /  /                 //
//      ========`-.____`-.________/___.-`____.-'========         //
//                           `=---='                              //
//      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
//            佛祖保佑       永不宕机     永无BUG                  //
////////////////////////////////////////////////////////////////////
${AnsiColor.BRIGHT_RED}
Application Version: ${application.version}${application.formatted-version}
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}

从上面的内容中可以看到,还支持对一些属性进行设置,下面是常用的几个配置:

${AnsiColor.BRIGHT_RED}:设置控制台中输出内容的颜色
${application.version}:用来获取MANIFEST.MF文件中的版本号
${application.formatted-version}:格式化后的${application.version}版本信息
${spring-boot.version}:Spring Boot的版本号
${spring-boot.formatted-version}:格式化后的${spring-boot.version}版本信息

在试验的时候,不知道咋回事application.version一直取不到值,也没深究,有机会再看看吧。

下面是效果图:

image.png

看起来还是挺有趣的~

2.0版本还支持了动态banner,在同样的位置添加一个gif即可。

image.png

banner.gif (220×190) (favorites.ren)

在启动之后,会先把gif一帧一帧的打印出来,最后显示banner.txt的内容

当然实际体验之后,感觉没啥用。。。

好了,今天就到这里了,我们下期再见👋🏻。