在2016年的最后一天,借用Spring Boot的Banner向各位程序猿同仁們問候一聲:Happy New Year。
接下來我們就來介紹一下這個輕松愉快的自定義banner功能。實現的方式非常簡單,我們只需要在Spring Boot工程的/src/main/resources目錄下創建一個banner.txt文件,然后將ASCII字符畫復制進去,就能替換默認的banner了。比如上圖中的輸出,就采用了下面的banner.txt內容:
- ${AnsiColor.BRIGHT_GREEN}
- ## ## ### ######## ######## ## ## ## ## ######## ## ## ## ## ######## ### ########
- ## ## ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ## #### #### ## ## ## ## ## #### ## ## ## ## ##
- ######### ## ## ######## ######## ## ## ## ## ###### ## ## ## ## ###### ## ## ########
- ## ## ######### ## ## ## ## #### ## ## ## ## ## ## ######### ## ##
- ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ## ## ######## ### ### ## ######## ## ## ## ##
- ${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}版本信息
生成工具
如果讓我們手工的來編輯這些字符畫,顯然是一件非常困難的差事。所以,我們可以借助下面這些工具,輕松地根據文字或圖片來生成用於Banner輸出的字符畫。
我比較喜歡這兩個字體
Font Name: Small Slant
Font Name: Slant
- http://patorjk.com/software/taag
- http://www.network-science.de/ascii/
- http://www.degraeve.com/img2txt.php
年終彩蛋
最后,奉上程序猿必備Banner “永不宕機佛祖”,祝大家:“新年快樂、永不宕機、永無Bug”!
- ${AnsiColor.BRIGHT_YELLOW}
- ////////////////////////////////////////////////////////////////////
- // _ooOoo_ //
- // o8888888o //
- // 88" . "88 //
- // (| ^_^ |) //
- // O\ = /O //
- // ____/`---'\____ //
- // .' \\| |// `. //
- // / \\||| : |||// \ //
- // / _||||| -:- |||||- \ //
- // | | \\\ - /// | | //
- // | \_| ''\---/'' | | //
- // \ .-\__ `-` ___/-. / //
- // ___`. .' /--.--\ `. . ___ //
- // ."" '< `.___\_<|>_/___.' >'"". //
- // | | : `- \`.;`\ _ /`;.`/ - ` : | | //
- // \ \ `-. \_ __\ /__ _/ .-` / / //
- // ========`-.____`-.___\_____/___.-`____.-'======== //
- // `=---=' //
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
- // 佛祖保佑 永不宕機 永無BUG //
- ////////////////////////////////////////////////////////////////////
效果圖:


