超個性修改SpringBoot項目的啟動banner的方法
如果我們使用過SpringBoot,那么就會對下面的圖案不陌生。Springboot 啟動的同時會打印下面的圖案,并帶有版本號。
查看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.
通過有道翻譯
可以通過向類路徑中添加一個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項目啟動后如下,這樣我們就修改了banner。
我們暫時刪除banner.txt文件,將下面圖片放置在類路徑下,名稱為:banner.jpg。
然后在配置文件中配置如下內(nèi)容
啟動SpringBoot項目后,圖案如下所示,Springboot把圖片轉(zhuǎn)成 ASCII圖案。
如果我們不想在啟動時出現(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啟動時就不會打印圖案了。
當(dāng)然,還有其他的方式改變以及關(guān)閉啟動的圖案,如果大家有不一樣的方式,可以在下方評論來說明。
相關(guān)文章
關(guān)于log4j日志擴(kuò)展---自定義PatternLayout
這篇文章主要介紹了關(guān)于log4j日志擴(kuò)展---自定義PatternLayout,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12Java8中Optional的一些常見錯誤用法總結(jié)
我們知道 Java 8 增加了一些很有用的 API, 其中一個就是 Optional,下面這篇文章主要給大家介紹了關(guān)于Java8中Optional的一些常見錯誤用法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-07-07