javascript
springboot banner在线生成_SpringBoot系列教程10--小花样之SpringBoot配置自定义Banner
SpringBoot系列教程10--小花樣之SpringBoot配置自定義Banner
作者:一一哥
一. Spring Boot 常用配置
本章節主要介紹一下 Spring Boot 中的一些常用配置,比如:自定義 Banner、配置日志、關閉特定的自動配置等.
在進行配置之前,我們還是結合之前的文章,先創建一個SpringBoot項目,然后進行本章節的學習。
二. 自定義 Banner
在 Spring Boot 啟動的時候會有一個默認的啟動圖案,被稱為Banner。
默認的Banner效果如下:
這個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目錄下,創建一個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,勾選,就可以關閉了!
最終的項目結構,可以參考如下圖!
總結
以上是生活随笔為你收集整理的springboot banner在线生成_SpringBoot系列教程10--小花样之SpringBoot配置自定义Banner的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图像处理 花屏_滴滴开源的 AoE:工程
- 下一篇: android数据回传多个页面_Andr