超個(gè)性修改SpringBoot項(xiàng)目的啟動(dòng)banner的方法
如果我們使用過(guò)SpringBoot,那么就會(huì)對(duì)下面的圖案不陌生。Springboot 啟動(dòng)的同時(shí)會(huì)打印下面的圖案,并帶有版本號(hào)。

查看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.
通過(guò)有道翻譯
可以通過(guò)向類(lèi)路徑中添加一個(gè)banner.txt文件或設(shè)置spring.banner來(lái)更改在console上打印的banner。屬性指向此類(lèi)文件的位置。如果文件的編碼不是UTF-8,那么可以設(shè)置spring.banner.charset。除了文本文件,還可以添加橫幅。將gif、banner.jpg或banner.png圖像文件保存到類(lèi)路徑或設(shè)置spring.banner.image。位置屬性。圖像被轉(zhuǎn)換成ASCII藝術(shù)形式,并打印在任何文本橫幅上面。
在IDEA中,在SpringBoot配置文件中輸入spring.banner會(huì)出現(xiàn)下面提示,正對(duì)應(yīng)上面翻譯的內(nèi)容。

1、自定義banner
我們?cè)陬?lèi)路徑下新建banner.txt文件,繪制下面圖案,下面地址就是繪制字符圖案。http://patorjk.com/software/taag/

SpringBoot項(xiàng)目啟動(dòng)后如下,這樣我們就修改了banner。

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

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

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

如果我們不想在啟動(dòng)時(shí)出現(xiàn)圖案,那么就需要修改SpringBoot啟動(dòng)類(lèi)的代碼
原代碼
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í)就不會(huì)打印圖案了。當(dāng)然,還有其他的方式改變以及關(guān)閉啟動(dòng)的圖案,如果大家有不一樣的方式,可以在下方評(píng)論來(lái)說(shuō)明。
相關(guān)文章:
1. CentOS郵箱服務(wù)器搭建系列——SMTP服務(wù)器的構(gòu)建( Postfix )2. PHP基礎(chǔ)之生成器4——比較生成器和迭代器對(duì)象3. ASP新手必備的基礎(chǔ)知識(shí)4. Docker 啟動(dòng)Redis 并設(shè)置密碼的操作5. asp文件用什么軟件編輯6. 通過(guò)IEAD+Maven快速搭建SSM項(xiàng)目的過(guò)程(Spring + Spring MVC + Mybatis)7. JS中6個(gè)對(duì)象數(shù)組去重的方法8. vue+element開(kāi)發(fā)一個(gè)谷歌插件的全過(guò)程9. 利用CSS制作3D動(dòng)畫(huà)10. Vue axios獲取token臨時(shí)令牌封裝案例

網(wǎng)公網(wǎng)安備