启动图案

Spring Boot在启动的时候会显示一个默认的Spring的图案,对应的类为SpringBootBanner。

.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.6.RELEASE)

图案输出有以下几种模式,默认是CONSOLE的,即只打印到控制台,也可以输出到日志文件。

enum Mode {

    /**
     * Disable printing of the banner.
     */
    OFF,

    /**
     * Print the banner to System.out.
     */
    CONSOLE,

    /**
     * Print the banner to the log file.
     */
    LOG

}

关闭图案

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        new SpringApplicationBuilder(Application.class).bannerMode(Banner.Mode.OFF)
                .run(args);
    }

}

定制图案

很简单,只要在classpath目录下创建banner.txt即可,把图案放入该文件就行,这是Spring Boot默认的图案位置,Spring Boot会自动加载该文件显示图案。

生成图案的网站:http://patorjk.com

也可以使用图片,更详细的可以研究Banner接口及其子类,不过这也没什么卵用,有兴趣的可以深入了解下。

当然也支持通过application配置文件来定制图案。

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

好了,今天的分享就到这里,更多 Spring Boot 文章正在撰写中,关注Java技术栈微信公众号获取第一时间推送。

在公众号后台回复:boot,还能获取栈长整理的往期 Spring Boot 教程,都是实战干货,以下仅为部分预览。

  • Spring Boot 读取配置的几种方式
  • Spring Boot 如何做参数校验?
  • Spring Boot 最核心的 25 个注解!
  • Spring Boot 2.x 启动全过程源码分析
  • Spring Boot 2.x 新特性总结及迁移指南
  • ……

本文原创首发于微信公众号:Java技术栈(id:javastack),转载请原样保留本信息。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注