zoukankan      html  css  js  c++  java
  • Spring Boot自定义Banner

    Spring Boot项目启动的时候会打印如下内容。

    1   .   ____          _            __ _ _
    2  /\ / ___'_ __ _ _(_)_ __  __ _    
    3 ( ( )\___ | '_ | '_| | '_ / _` |    
    4  \/  ___)| |_)| | | | | || (_| |  ) ) ) )
    5   '  |____| .__|_| |_|_| |_\__, | / / / /
    6  =========|_|==============|___/=/_/_/_/
    7  :: Spring Boot ::        (v2.1.4.RELEASE)

    我们要怎么自定义打印的内容呢?

    自定义Banner非常简单,只需在 classpath ( src/main/resources )下创建创建名为 banner.txt 的文件,然后在banner.txt写入自己想要打印的内容即可。

    比如:

     1                     _ooOoo_
     2                    o8888888o
     3                    88" . "88
     4                    (| ^_^ |)
     5                    O  =  /O
     6                 ____/`---'\____
     7               .'  \|     |//  `.
     8              /  \|||  :  |||//  
     9             /  _||||| -:- |||||-  
    10             |   | \  -  /// |   |
    11             | \_|  ''---/''  |   |
    12               .-\__  `-`  ___/-. /
    13           ___`. .'  /--.--  `. . ___
    14         ."" '<  `.___\_<|>_/___.'  >'"".
    15       | | :  `- \`.;` _ /`;.`/ - ` : | |
    16 ========`-.____`-.___\_____/___.-`____.-'========
    17          `-.   \_ __ /__ _/   .-` /  /
    18                      `=---='
    19 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    20          佛祖保佑       永不宕机       永无Bug

    如何打印项目相关的信息?

    banner.txt 支持占位符,占位符可用于描述项目,同时也可定制Banner显示的具体细节。

    允许使用的占位符如下表所示:

    VariableDescription
    ${application.version} 应用版本,从MANIFEST.MF 读取Implementation-Version 的值并显示。例如Implementation-Version: 1.0 ,则打印 1.0
    ${application.formatted-version} 将应用版本用括号括起来,并添加前缀v。例如:Implementation-Version: 1.0 ,则打印 (v1.0)
    ${spring-boot.version} 打印Spring Boot版本,例如 2.1.4.RELEASE
    ${spring-boot.formatted-version} 将Spring Boot版本用括号括起来,并添加前缀v。例如: (v2.1.4.RELEASE)
    ${Ansi.NAME} (or ${AnsiColor.NAME}${AnsiBackground.NAME}${AnsiStyle.NAME}) 指定ANSI转义码,详见 org.springframework.boot.ansi.AnsiPropertySource
    ${application.title} 应用标题,从 MANIFEST.MF 读取 Implementation-Title 的值并打印。例如 Implementation-Title: itmuch-app ,则打印 itmuch-app 。

    比如:

     1 ${AnsiColor.GREEN}
     2                     _ooOoo_
     3                    o8888888o
     4                    88" . "88
     5                    (| ^_^ |)
     6                    O  =  /O
     7                 ____/`---'\____
     8               .'  \|     |//  `.
     9              /  \|||  :  |||//  
    10             /  _||||| -:- |||||-  
    11             |   | \  -  /// |   |
    12             | \_|  ''---/''  |   |
    13               .-\__  `-`  ___/-. /
    14           ___`. .'  /--.--  `. . ___
    15         ."" '<  `.___\_<|>_/___.'  >'"".
    16       | | :  `- \`.;` _ /`;.`/ - ` : | |
    17 ========`-.____`-.___\_____/___.-`____.-'========
    18          `-.   \_ __ /__ _/   .-` /  /
    19                      `=---='
    20 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    21          佛祖保佑       永不宕机       永无Bug
    22 ==================================================
    23 Application Info:${application.title}-${application.version}
    24 Powered by:Spring Boot ${spring-boot.version}

    怎么禁用Banner?

    添加如下配置:

    1 spring:
    2   main:
    3     banner-mode: "off"

    或在启动类上添加类似如下代码:

    1 public static void main(String[] args) {
    2     SpringApplication app = new SpringApplication(MySpringConfiguration.class);
    3     app.setBannerMode(Banner.Mode.OFF);
    4     app.run(args);
    5 }

    附上我使用的Banner:

    ======Powered by:Spring Boot ${spring-boot.version}======
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| ^_^ |)
                       O  =  /O
                    ____/`---'\____
                  .'  \|     |//  `.
                 /  \|||  :  |||//  
                /  _||||| -:- |||||-  
                |   | \  -  /// |   |
                | \_|  ''---/''  |   |
                  .-\__  `-`  ___/-. /
              ___`. .'  /--.--  `. . ___
            ."" '<  `.___\_<|>_/___.'  >'"".
          | | :  `- \`.;` _ /`;.`/ - ` : | |
    ========`-.____`-.___\_____/___.-`____.-'========
             `-.   \_ __ /__ _/   .-` /  /
                         `=---='
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          佛祖保佑       永不宕机       永无Bug

    结束语:重要的不是你从哪里来,而是你到哪里去,找准方向,继续努力。

    佛系博主:AlanLee

    博客地址:http://www.cnblogs.com/AlanLee

    GitHub地址:https://github.com/AlanLee-Java

    本文出自博客园,欢迎大家加入博客园。

  • 相关阅读:
    SpringBoot 项目集成增强版 SwaggerKnife4j 附常见问题及解决方案
    ZooKeeper 06 ZooKeeper 的常用命令
    ZooKeeper 04 ZooKeeper 集群的节点为什么必须是奇数个
    TCP扫描增强器实现65000端口,10S完成,快准狠(Go语言编程)
    集群服务器的网络连接状态接入ELK(可视化操作)
    golang的ping检测主机存活
    Gin编写邮件告警接口(添加配置,项目拆分)
    Gin编写邮件接口(支持多人发送)
    Linux操作系统账号密码失效检测
    Rsyslog同步集群服务器的网络连接状态
  • 原文地址:https://www.cnblogs.com/AlanLee/p/12905700.html
Copyright © 2011-2022 走看看