idea設置springboot控制台打印logo(banner.txt文件)


參考博客(huanzi-qch):https://www.cnblogs.com/huanzi-qch/p/9916784.html

項目結構

我們只需要在springboot項目的resources文件夾下面創建一個banner.txt文件,springboot啟動的時候會去加載這個文件,項目結構:

 

 

banner.txt

  這里有幾個定制banner的網站,文字、圖片都可以秀起來,怎么秀就看你的騷操作了

  http://patorjk.com/software/taag

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

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

  

  banner.txt的內容:

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

  banner.txt配置

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

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

  ${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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM