Spring Boot專案啟動的時候會列印如下內容,
1 . ____ _ __ _ _ 2 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ 3 ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ 4 \\/ ___)| |_)| | | | | || (_| | ) ) ) ) 5 ' |____| .__|_| |_|_| |_\__, | / / / / 6 =========|_|==============|___/=/_/_/_/ 7 :: Spring Boot :: (v2.1.4.RELEASE)
我們要怎么自定義列印的內容呢?
自定義Banner非常簡單,只需在 classpath ( src/main/resources )下創建創建名為 banner.txt 的檔案,然后在banner.txt寫入自己想要列印的內容即可,
比如:
1 _ooOoo_ 2 o8888888o 3 88" . "88 4 (| ^_^ |) 5 O\ = /O 6 ____/`---'\____ 7 .' \\| |// `. 8 / \\||| : |||// \ 9 / _||||| -:- |||||- \ 10 | | \\\ - /// | | 11 | \_| ''\---/'' | | 12 \ .-\__ `-` ___/-. / 13 ___`. .' /--.--\ `. . ___ 14 ."" '< `.___\_<|>_/___.' >'"". 15 | | : `- \`.;`\ _ /`;.`/ - ` : | | 16 ========`-.____`-.___\_____/___.-`____.-'======== 17 \ \ `-. \_ __\ /__ _/ .-` / / 18 `=---=' 19 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20 佛祖保佑 永不宕機 永無Bug
如何列印專案相關的資訊?
banner.txt 支持占位符,占位符可用于描述專案,同時也可定制Banner顯示的具體細節,
允許使用的占位符如下表所示:
| Variable | Description |
|---|---|
${application.version} |
應用版本,從MANIFEST.MF 讀取Implementation-Version 的值并顯示,例如Implementation-Version: 1.0 ,則列印 1.0 |
${application.formatted-version} |
將應用版本用括號括起來,并添加前綴v,例如:Implementation-Version: 1.0 ,則列印 (v1.0) |
${spring-boot.version} |
列印Spring Boot版本,例如 2.1.4.RELEASE |
${spring-boot.formatted-version} |
將Spring Boot版本用括號括起來,并添加前綴v,例如: (v2.1.4.RELEASE) |
${Ansi.NAME} (or ${AnsiColor.NAME}, ${AnsiBackground.NAME}, ${AnsiStyle.NAME}) |
指定ANSI轉義碼,詳見 org.springframework.boot.ansi.AnsiPropertySource |
${application.title} |
應用標題,從 MANIFEST.MF 讀取 Implementation-Title 的值并列印,例如 Implementation-Title: itmuch-app ,則列印 itmuch-app , |
比如:
1 ${AnsiColor.GREEN} 2 _ooOoo_ 3 o8888888o 4 88" . "88 5 (| ^_^ |) 6 O\ = /O 7 ____/`---'\____ 8 .' \\| |// `. 9 / \\||| : |||// \ 10 / _||||| -:- |||||- \ 11 | | \\\ - /// | | 12 | \_| ''\---/'' | | 13 \ .-\__ `-` ___/-. / 14 ___`. .' /--.--\ `. . ___ 15 ."" '< `.___\_<|>_/___.' >'"". 16 | | : `- \`.;`\ _ /`;.`/ - ` : | | 17 ========`-.____`-.___\_____/___.-`____.-'======== 18 \ \ `-. \_ __\ /__ _/ .-` / / 19 `=---=' 20 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 21 佛祖保佑 永不宕機 永無Bug 22 ================================================== 23 Application Info:${application.title}-${application.version} 24 Powered by:Spring Boot ${spring-boot.version}
怎么禁用Banner?
添加如下配置:
1 spring: 2 main: 3 banner-mode: "off"
或在啟動類上添加類似如下代碼:
1 public static void main(String[] args) { 2 SpringApplication app = new SpringApplication(MySpringConfiguration.class); 3 app.setBannerMode(Banner.Mode.OFF); 4 app.run(args); 5 }
附上我使用的Banner:
======Powered by:Spring Boot ${spring-boot.version}======
_ooOoo_
o8888888o
88" . "88
(| ^_^ |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . ___
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
========`-.____`-.___\_____/___.-`____.-'========
\ \ `-. \_ __\ /__ _/ .-` / /
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
佛祖保佑 永不宕機 永無Bug
結束語:重要的不是你從哪里來,而是你到哪里去,找準方向,繼續努力,
佛系博主:AlanLee
博客地址:http://www.cnblogs.com/AlanLee
GitHub地址:https://github.com/AlanLee-Java
本文出自博客園,歡迎大家加入博客園,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/191474.html
標籤:Java
上一篇:java“單根繼承結構”
下一篇:Spring Boot發送郵件
