SpringBoot系列——花裏胡哨的banner.txt

  前言

  咱們注意到springboot項目啓動時,控制檯會打印自帶的banner,而後對於部分IT騷年來講,太單調太普通太通常了;因此,是時候表演真正的技術了php

 

   項目結構

  咱們只須要在springboot項目的resources文件夾下面建立一個banner.txt文件,springboot啓動的時候會去加載這個文件,項目結構:html

 

   banner.txt

  這裏有幾個定製banner的網站,文字、圖片均可以秀起來,怎麼秀就看你的騷操做了git

  http://patorjk.com/software/taaggithub

  http://www.network-science.de/ascii/spring

  http://www.degraeve.com/img2txt.phpspringboot

  

  banner.txt的內容:app

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

  banner.txt配置socket

  ${AnsiColor.BRIGHT_RED}:設置控制檯中輸出內容的顏色ide

  ${application.version}:用來獲取MANIFEST.MF文件中的版本號spring-boot

  ${application.formatted-version}:格式化後的${application.version}版本信息

  ${spring-boot.version}:Spring Boot的版本號

  ${spring-boot.formatted-version}:格式化後的${spring-boot.version}版本信息

 

  spring對banner的配置,來自springboot參考手冊,Common application properties:https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/htmlsingle/#common-application-properties

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

 

  效果 

 

  結束語

  秀兒,是你嗎?

  banner默認開啓,若是不想讓它打印怎麼辦?

  方法1,在main的run方法設置

/** * 啓動主類,springboot的入口 * springboot 默認掃描的類是在啓動類的當前包和下級包 */ @SpringBootApplication public class SpringbootWebsocketSpringdataJpaApplication { public static void main(String[] args) { SpringApplication springApplication = new SpringApplication(SpringbootWebsocketSpringdataJpaApplication.class); //Banner.Mode.OFF 關閉
 springApplication.setBannerMode(Banner.Mode.OFF); springApplication.run(args); } }

   方法2,Edit Configurations --> 勾選Hide banner

 

  代碼開源

  代碼已經開源、託管到個人GitHub、碼雲:

  GitHub:https://github.com/huanzi-qch/springBoot

  碼雲:https://gitee.com/huanzi-qch/springBoot

相關文章
相關標籤/搜索