32

springboot入门10 – 修改banner

 4 years ago
source link: https://www.zhyea.com/2020/03/21/springboot-basic-10-change-banner.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

这个内容有点儿水了。但是将springboot启动时的banner修改一下是个蛮好玩的事情。比如,不知道什么时候,我们组的springboot应用的banner就被改成了这个样子:

////////////////////////////////////////////////////////////////////  
//                          _ooOoo_                               //  
//                         o8888888o                              //  
//                         88" . "88                              //  
//                         (| ^_^ |)                              //  
//                         O\  =  /O                              //  
//                      ____/`---'\____                           //  
//                    .'  \\|     |//  `.                         //  
//                   /  \\|||  :  |||//  \                        //  
//                  /  _||||| -:- |||||-  \                       //  
//                  |   | \\\  -  /// |   |                       //  
//                  | \_|  ''\---/''  |   |                       //  
//                  \  .-\__  `-`  ___/-. /                       //  
//                ___`. .'  /--.--\  `. . ___                     //  
//              ."" '<  `.___\_<|>_/___.'  >'"".                  //  
//            | | :  `- `.;`\ _ /`;.`/ - ` : | |                 //  
//            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //  
//      ========`-.____`-.___\_____/___.-`____.-'========         //  
//                           `=---='                              //  
//      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //  
//            佛祖保佑       永不宕机      永无BUG                  //
////////////////////////////////////////////////////////////////////

据说改了之后BUG真的少了耶!(*/ω\*)

修改方式也比较简单,创建一个名为banner.txt的文件,写入图标字符,然后将这个文件放到resource目录下。搞定了。就这样。

不过,springboot还是提供了一些配置信息的。下面是可以在banner.txt中使用的一些替换宏:

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

还有一些其它替换宏,在idea中编辑banner.txt文档的时候这些都有动态提示。

还有一些在application中使用的配置:

# BANNER
spring.banner.charset=UTF-8 # Banner file encoding.
spring.banner.location=classpath:banner.txt # Banner text resource location.
spring.banner.image.location=classpath:banner.gif # Banner image file location (jpg or png can also be used).
spring.banner.image.width=76 # Width of the banner image in chars.
spring.banner.image.height= # Height of the banner image in chars (default based on image height).
spring.banner.image.margin=2 # Left hand image margin in chars.
spring.banner.image.invert=false # Whether images should be inverted for dark terminal themes.

最后记录几个生成ascii字符图像的网站(话说这也是我写这篇文的初衷):

  • 图像转字符图像:https://www.degraeve.com/img2txt.php
  • 文字转字符图像:http://patorjk.com/software/taag

End!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK