Spring Boot自定義Banner

在2016年的最後一天,借用Spring Boot的Banner向各位程序猿同仁們問候一聲:Happy New Year。php

接下來咱們就來介紹一下這個輕鬆愉快的自定義banner功能。實現的方式很是簡單,咱們只須要在Spring Boot工程的/src/main/resources目錄下建立一個banner.txt文件,而後將ASCII字符畫複製進去,就能替換默認的banner了。好比上圖中的輸出,就採用了下面的banner.txt內容:html

[html]  view plain  copy
 
  1. ${AnsiColor.BRIGHT_GREEN}  
  2. ##     ##    ###    ########  ########  ##    ##    ##    ## ######## ##      ##    ##    ## ########    ###    ########  
  3. ##     ##   ## ##   ##     ## ##     ##  ##  ##     ###   ## ##       ##  ##  ##     ##  ##  ##         ## ##   ##     ##  
  4. ##     ##  ##   ##  ##     ## ##     ##   ####      ####  ## ##       ##  ##  ##      ####   ##        ##   ##  ##     ##  
  5. ######### ##     ## ########  ########     ##       ## ## ## ######   ##  ##  ##       ##    ######   ##     ## ########  
  6. ##     ## ######### ##        ##           ##       ##  #### ##       ##  ##  ##       ##    ##       ######### ##   ##  
  7. ##     ## ##     ## ##        ##           ##       ##   ### ##       ##  ##  ##       ##    ##       ##     ## ##    ##  
  8. ##     ## ##     ## ##        ##           ##       ##    ## ########  ###  ###        ##    ######## ##     ## ##     ##  
  9. ${AnsiColor.BRIGHT_RED}  
  10. Application Version: ${application.version}${application.formatted-version}  
  11. Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}  

 

從上面的內容中能夠看到,還使用了一些屬性設置:spring

  • ${AnsiColor.BRIGHT_RED}:設置控制檯中輸出內容的顏色
  • ${application.version}:用來獲取MANIFEST.MF文件中的版本號
  • ${application.formatted-version}:格式化後的${application.version}版本信息
  • ${spring-boot.version}:Spring Boot的版本號
  • ${spring-boot.formatted-version}:格式化後的${spring-boot.version}版本信息

生成工具

若是讓咱們手工的來編輯這些字符畫,顯然是一件很是困難的差事。因此,咱們能夠藉助下面這些工具,輕鬆地根據文字或圖片來生成用於Banner輸出的字符畫。app

我比較喜歡這兩個字體spring-boot

Font Name: Small Slant
Font Name: Slant工具

年終彩蛋

最後,奉上程序猿必備Banner 「永不宕機佛祖」,祝你們:「新年快樂、永不宕機、永無Bug」!字體

[html]  view plain  copy
 
  1. ${AnsiColor.BRIGHT_YELLOW}  
  2. ////////////////////////////////////////////////////////////////////  
  3. //                          _ooOoo_                               //  
  4. //                         o8888888o                              //  
  5. //                         88" . "88                              //  
  6. //                         (| ^_^ |)                              //  
  7. //                         O\  =  /O                              //  
  8. //                      ____/`---'\____                           //  
  9. //                    .'  \\|     |//  `.                         //  
  10. //                   /  \\|||  :  |||//  \                        //  
  11. //                  /  _||||| -:- |||||-  \                       //  
  12. //                  |   | \\\  -  /// |   |                       //  
  13. //                  | \_|  ''\---/''  |   |                       //  
  14. //                  \  .-\__  `-`  ___/-. /                       //  
  15. //                ___`. .'  /--.--\  `. . ___                     //  
  16. //              ."" '<  `.___\_<|>_/___.'  >'"".                  //  
  17. //            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //  
  18. //            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //  
  19. //      ========`-.____`-.___\_____/___.-`____.-'========         //  
  20. //                           `=---='                              //  
  21. //      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //  
  22. //            佛祖保佑       永不宕機     永無BUG                  //  
  23. ////////////////////////////////////////////////////////////////////  

 

效果圖:spa

相關文章
相關標籤/搜索