spring-boot定制启动图案

本文来源微信公众号:Java技术栈(公众号ID:javastack):转载请注明原文出处,谢谢!

spring-boot定制启动图案

 

 

spring-boot定制启动图案

 

启动图案

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

 
  1. .   ____          _            __ _ _

  2. /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \

  3. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \

  4. \\/  ___)| |_)| | | | | || (_| |  ) ) ) )

  5.  '  |____| .__|_| |_|_| |_\__, | / / / /

  6. =========|_|==============|___/=/_/_/_/

  7. :: Spring Boot ::        (v1.5.6.RELEASE)

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

 
  1. enum Mode {

  2.  

  3.    /**

  4.     * Disable printing of the banner.

  5.     */

  6.    OFF,

  7.  

  8.    /**

  9.     * Print the banner to System.out.

  10.     */

  11.    CONSOLE,

  12.  

  13.    /**

  14.     * Print the banner to the log file.

  15.     */

  16.    LOG

  17.  

  18. }

关闭图案

 
  1. @SpringBootApplication

  2. public class Application {

  3.  

  4.    public static void main(String[] args) {

  5.        new SpringApplicationBuilder(Application.class).bannerMode(Banner.Mode.OFF)

  6.                .run(args);

  7.    }

  8.  

  9. }

定制图案

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

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

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

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

 
  1. # BANNER

  2. banner.charset=UTF-8 # Banner file encoding.

  3. banner.location=classpath:banner.txt # Banner file location.

  4. banner.image.location=classpath:banner.gif # Banner image file location (jpg/png can also be used).

  5. banner.image.width= # Width of the banner image in chars (default 76)

  6. banner.image.height= # Height of the banner image in chars (default based on image height)

  7. banner.image.margin= # Left hand image margin in chars (default 2)

  8. banner.image.invert= # If images should be inverted for dark terminal themes (default false)

 

spring-boot定制启动图案