SpringBoot之个性化Banner

SpringBoot花里胡哨的启动图像
  • 我们注意到springboot项目启动时,控制台会打印自带的banner,然后对于部分IT骚年来说,太单调太普通太一般了;所以,是时候表演真正的技术了
  • SpringBoot 有一个接口 org.springframework.boot.Banner 是专门来做这个操作的。我们可以实现这个接口来自定义打印 Banner 信息;但是没必要。我们只需要会使用这个骚操作就好了。
  • 话不多说,先上图为敬
    在这里插入图片描述
那么,我们怎么实现呢?
  • 只需要在springboot项目的resources文件夹下面创建一个banner.txt文件,springboot启动的时候会去加载这个文件
  • banner.txt
Spring Boot Version: ${spring-boot.version}
////////////////////////////////////////////////////////////////////
//                          _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}版本信息
关闭banner
  • banner默认开启,如果不想让它打印怎么办?
    • 方法1,在main的run方法设置
    /**
     * 启动主类,springboot的入口
     * springboot 默认扫描的类是在启动类的当前包和下级包
     */
    @SpringBootApplication
    public class SpringbootApp {
    
        public static void main(String[] args) {
            SpringApplication springApplication = new SpringApplication(SpringbootApp.class);
            //Banner.Mode.OFF 关闭
            springApplication.setBannerMode(Banner.Mode.OFF);
            springApplication.run(args);
        }
    }
    
    • 方法2,Edit Configurations --> 勾选Hide banner
      在这里插入图片描述
banner.txt
  • 这里有几个定制banner的网站,文字、图片都可以秀起来,怎么秀就看你的骚操作了
    • http://patorjk.com/software/taag
    • http://www.network-science.de/ascii/
    • http://www.degraeve.com/img2txt.php

你知道的越多,你不知道的越多。
有道无术,术尚可求,有术无道,止于术。
如有其它问题,欢迎大家留言,我们一起讨论,一起学习,一起进步

发布了193 篇原创文章 · 获赞 116 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_40722827/article/details/104983459
今日推荐