超個(gè)性修改SpringBoot項(xiàng)目的啟動(dòng)banner的方法
如果我們使用過SpringBoot,那么就會對下面的圖案不陌生。Springboot 啟動(dòng)的同時(shí)會打印下面的圖案,并帶有版本號。
查看SpringBoot官方文檔可以找到關(guān)于 banner 的描述
The banner that is printed on start up can be changed by adding a banner.txt file to your classpath or by setting the spring.banner.location property to the location of such a file. If the file has an encoding other than UTF-8, you can set spring.banner.charset. In addition to a text file, you can also add a banner.gif, banner.jpg, or banner.png image file to your classpath or set the spring.banner.image.location property. Images are converted into an ASCII art representation and printed above any text banner.
通過有道翻譯
可以通過向類路徑中添加一個(gè)banner.txt文件或設(shè)置spring.banner來更改在console上打印的banner。屬性指向此類文件的位置。如果文件的編碼不是UTF-8,那么可以設(shè)置spring.banner.charset。除了文本文件,還可以添加橫幅。將gif、banner.jpg或banner.png圖像文件保存到類路徑或設(shè)置spring.banner.image。位置屬性。圖像被轉(zhuǎn)換成ASCII藝術(shù)形式,并打印在任何文本橫幅上面。
在IDEA中,在SpringBoot配置文件中輸入spring.banner會出現(xiàn)下面提示,正對應(yīng)上面翻譯的內(nèi)容。
1、自定義banner
我們在類路徑下新建banner.txt文件,繪制下面圖案,下面地址就是繪制字符圖案。
http://patorjk.com/software/taag/
SpringBoot項(xiàng)目啟動(dòng)后如下,這樣我們就修改了banner。
我們暫時(shí)刪除banner.txt文件,將下面圖片放置在類路徑下,名稱為:banner.jpg。
然后在配置文件中配置如下內(nèi)容
啟動(dòng)SpringBoot項(xiàng)目后,圖案如下所示,Springboot把圖片轉(zhuǎn)成 ASCII圖案。
如果我們不想在啟動(dòng)時(shí)出現(xiàn)圖案,那么就需要修改SpringBoot啟動(dòng)類的代碼
原代碼
public static void main(String[] args) { SpringApplication.run(SpringbootShiroApplication.class, args); }
修改后的代碼
public static void main(String[] args) { SpringApplication app = new SpringApplication(SpringbootShiroApplication.class); app.setBannerMode(Banner.Mode.OFF); app.run(args); }
這樣,SpringBoot啟動(dòng)時(shí)就不會打印圖案了。
當(dāng)然,還有其他的方式改變以及關(guān)閉啟動(dòng)的圖案,如果大家有不一樣的方式,可以在下方評論來說明。
相關(guān)文章
Java版仿QQ驗(yàn)證碼風(fēng)格圖片驗(yàn)證碼
這篇文章主要為大家分享了java圖片驗(yàn)證碼實(shí)例代碼,感興趣的小伙伴們可以參考一下2016-04-04關(guān)于log4j日志擴(kuò)展---自定義PatternLayout
這篇文章主要介紹了關(guān)于log4j日志擴(kuò)展---自定義PatternLayout,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12Springboot項(xiàng)目Maven依賴沖突的問題解決
使用Spring Boot和Maven進(jìn)行項(xiàng)目開發(fā)時(shí),依賴沖突是一個(gè)常見的問題,本文就來介紹一下Springboot項(xiàng)目Maven依賴沖突的問題解決,具有一定的參考價(jià)值,感興趣的可以了解一下2024-07-07Java8中Optional的一些常見錯(cuò)誤用法總結(jié)
我們知道 Java 8 增加了一些很有用的 API, 其中一個(gè)就是 Optional,下面這篇文章主要給大家介紹了關(guān)于Java8中Optional的一些常見錯(cuò)誤用法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-07-07