ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

SpringBoot系列之banner.txt (转)

2021-08-16 17:04:15  阅读:239  来源: 互联网

标签:SpringBoot spring image version txt banner springboot


前言

  我们注意到springboot项目启动时,控制台会打印自带的banner,然后对于部分IT骚年来说,太单调太普通太一般了;所以,是时候表演真正的技术了

项目结构

  我们只需要在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}版本信息

 

pring对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=100                         # 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:

版权声明

作者:huanzi-qch 出处:https://www.cnblogs.com/huanzi-qch 若标题中有“转载”字样,则本文版权归原作者所有。若无转载字样,本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利.

标签:SpringBoot,spring,image,version,txt,banner,springboot
来源: https://www.cnblogs.com/cy0628/p/15148681.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有