溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么修改SpringBoot項(xiàng)目啟動(dòng)banner

發(fā)布時(shí)間:2022-04-07 14:25:39 來源:億速云 閱讀:512 作者:iii 欄目:編程語言

這篇文章主要介紹“怎么修改SpringBoot項(xiàng)目啟動(dòng)banner”的相關(guān)知識(shí),小編通過實(shí)際案例向大家展示操作過程,操作方法簡(jiǎn)單快捷,實(shí)用性強(qiáng),希望這篇“怎么修改SpringBoot項(xiàng)目啟動(dòng)banner”文章能幫助大家解決問題。

如果我們使用過SpringBoot,那么就會(huì)對(duì)下面的圖案不陌生。Springboot 啟動(dòng)的同時(shí)會(huì)打印下面的圖案,并帶有版本號(hào)。

怎么修改SpringBoot項(xiàng)目啟動(dòng)banner

查看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會(huì)出現(xiàn)下面提示,正對(duì)應(yīng)上面翻譯的內(nèi)容。

怎么修改SpringBoot項(xiàng)目啟動(dòng)banner

1、自定義banner

我們?cè)陬惵窂较滦陆╞anner.txt文件,繪制下面圖案。

怎么修改SpringBoot項(xiàng)目啟動(dòng)banner

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

怎么修改SpringBoot項(xiàng)目啟動(dòng)banner

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

怎么修改SpringBoot項(xiàng)目啟動(dòng)banner

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

怎么修改SpringBoot項(xiàng)目啟動(dòng)banner

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

怎么修改SpringBoot項(xiàng)目啟動(dòng)banner

如果我們不想在啟動(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í)就不會(huì)打印圖案了。

關(guān)于“怎么修改SpringBoot項(xiàng)目啟動(dòng)banner”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI