日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringBoot2.x系列教程10--小花样之SpringBoot配置自定义Banner

發(fā)布時間:2023/12/20 javascript 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot2.x系列教程10--小花样之SpringBoot配置自定义Banner 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

SpringBoot系列教程10--小花樣之SpringBoot配置自定義Banner

作者:一一哥

一. Spring Boot 常用配置

本章節(jié)主要介紹一下 Spring Boot 中的一些常用配置,比如:自定義 Banner、配置日志、關閉特定的自動配置等.

在進行配置之前,我們還是結合之前的文章,先創(chuàng)建一個SpringBoot項目,然后進行本章節(jié)的學習。

二. 自定義 Banner

在 Spring Boot 啟動的時候會有一個默認的啟動圖案,被稱為Banner。
默認的Banner效果如下:

. ____ _ __ _ _/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/ ___)| |_)| | | | | || (_| | ) ) ) )' |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot :: (v1.5.8.RELEASE)

這個Banner是Spring Boot自帶的,如果我們覺得不好看,是可以更改的,作為一個資深的碼農,怎么可以不定制一個自己的Banner呢?

1.新建一個banner.txt

我們在?src/main/resources?目錄下新建一個 banner.txt

我們可以通過?http://patorjk.com/software/taag?這個網站,來生成自定義的banner字符串,將網站生成的字符復制到 banner.txt 中就可以啦.

2.再次運行這個程序,控制臺出現如下界面.

${AnsiColor.BLUE} ${spring-boot.version} ${spring-boot.formatted-version}// _ooOoo_ // // o8888888o // // 88" . "88 // // (| ^_^ |) // // O\ = /O // // ____/`---'\____ // // .' \\| |// `. // // / \\||| : |||// \ // // / _||||| -:- |||||- \ // // | | \\\ - /// | | // // | \_| ''\---/'' | | // // \ .-\__ `-` ___/-. / // // ___`. .' /--.--\ `. . ___ // // ."" '< `.___\_<|>_/___.' >'"". // // | | : `- \`.;`\ _ /`;.`/ - ` : | | // // \ \ `-. \_ __\ /__ _/ .-` / / // // ========`-.____`-.___\_____/___.-`____.-'======== // // `=---=' // // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // // 佛祖保佑 永不宕機 永無BUG   //

3.常用Banner設置屬性

  • ${AnsiColor.BRIGHT_RED}: 設置控制臺中輸出內容的顏色;
  • ${application.version}:用來獲取?MANIFEST.MF?文件中的版本號;
  • ${application.formatted-version}: 格式化后的?${application.version}?版本信息;
  • ${spring-boot.version}: Spring Boot 的版本號;
  • ${spring-boot.formatted-version}: 格式化后的?${spring-boot.version}?版本信息.

4.Banner其他配置

我們可以在application.properties中,進行一些banner的基本屬性配置。

我們在src/main/resources目錄下,創(chuàng)建一個application.properties配置文件,在該文件中可以添加如下配置信息:

# BANNER #Banner file encoding. spring.banner.charset=UTF-8 #Banner text resource location. spring.banner.location=classpath:banner.txt #Banner image file location (jpg or png can also be used). spring.banner.image.location=classpath:banner.gif #Width of the banner image in chars. spring.banner.image.width=76 #Height of the banner image in chars (default based on image height). spring.banner.image.height= #Left hand image margin in chars spring.banner.image.margin=2 #Whether images should be inverted for dark terminal themes. spring.banner.image.invert=false

這些配置信息,主要是對banner的寬度高度等屬性進行設置。

5.關閉Banner

如果我們不想啟動項目的時候展示Banner,也可以關閉掉,畢竟這東西沒啥作用,典型的屬于奇技淫巧。

5.1 代碼方式關閉

我們可以在Application入口類中設置Banner的啟動模式,默認是開啟的,可以關閉掉。

@SpringBootApplication public class BannerApplication {public static void main(String[] args) {//SpringApplication.run(BannerApplication.class, args);SpringApplication application=new SpringApplication(BannerApplication.class);//設置banner模式,不需要打印banner可以關閉,默認是開啟的application.setBannerMode(Banner.Mode.CONSOLE);application.run(args);} }

通過調用setBannerMode()方法,可以設置將banner打印console,log,或者不輸出off。

5.2 yml文件配置

我們也可以在yml文件中,設置banner的模式,注意在yml文件中,會將off映射為false,并且需要給off添加括號:

spring:main:banner-mode: "off"

5.3 配置方式關閉

這種方式就不用每次都寫代碼了,可以在每個項目的Edit Configurations中的spring boot選型里,找到Hide Banner,勾選,就可以關閉了!

最終的項目結構,可以參考如下圖!

總結

以上是生活随笔為你收集整理的SpringBoot2.x系列教程10--小花样之SpringBoot配置自定义Banner的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。