超個(gè)性修改SpringBoot項(xiàng)目的啟動banner的方法
如果我們使用過SpringBoot,那么就會對下面的圖案不陌生。Springboot 啟動的同時(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)目啟動后如下,這樣我們就修改了banner。

我們暫時(shí)刪除banner.txt文件,將下面圖片放置在類路徑下,名稱為:banner.jpg。

然后在配置文件中配置如下內(nèi)容

啟動SpringBoot項(xiàng)目后,圖案如下所示,Springboot把圖片轉(zhuǎn)成 ASCII圖案。

如果我們不想在啟動時(shí)出現(xiàn)圖案,那么就需要修改SpringBoot啟動類的代碼
原代碼
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啟動時(shí)就不會打印圖案了。
當(dāng)然,還有其他的方式改變以及關(guān)閉啟動的圖案,如果大家有不一樣的方式,可以在下方評論來說明。
相關(guān)文章
如何解決通過spring-boot-maven-plugin package失敗問題
這篇文章主要介紹了如何解決通過spring-boot-maven-plugin package失敗問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04
Java之synchronized(含與ReentrantLock的區(qū)別解讀)
文章主要介紹了`synchronized`和`ReentrantLock`的區(qū)別,包括它們的實(shí)現(xiàn)原理、公平性、靈活性、可中斷性等方面,同時(shí),文章詳細(xì)解釋了`synchronized`的使用方法,包括修飾實(shí)例方法、靜態(tài)方法和代碼塊的情況,以及如何分析代碼是否互斥和可重入性2025-01-01
SpringBoot整合Ureport2報(bào)表及常見使用方法
這篇文章主要介紹了SpringBoot整合Ureport2報(bào)表及常見使用方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
SpringBoot JPA懶加載失效的解決方案(親測有效)
這篇文章主要介紹了SpringBoot JPA懶加載失效的解決方案(親測有效),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-08-08
基于Quartz定時(shí)調(diào)度任務(wù)(詳解)
下面小編就為大家?guī)硪黄赒uartz定時(shí)調(diào)度任務(wù)(詳解)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11

