Spring Boot 2.x 系列--自定义banner

自定义banner:  

spring boot 默认启动时显示的横幅如下

Spring Boot 2.x 系列--自定义banner_第1张图片

怎么自定义:   首先在resources下创建 banner.txt

Spring Boot 2.x 系列--自定义banner_第2张图片

banner里面变量介绍

变量 描述

${application.version}

您声明的应用程序的版本号MANIFEST.MF。例如,Implementation-Version: 1.0打印为1.0

${application.formatted-version}

应用程序的版本号,在声明中MANIFEST.MF显示并格式化以显示(用括号括起来并带有前缀v)。例如(v1.0)

${spring-boot.version}

您正在使用的Spring Boot版本。例如2.1.0.RELEASE

${spring-boot.formatted-version}

您正在使用的Spring Boot版本,格式化显示(用括号括起来并带有前缀v)。例如(v2.1.0.RELEASE)

${Ansi.NAME}(或${AnsiColor.NAME}${AnsiBackground.NAME}${AnsiStyle.NAME}

NAMEANSI转义码的名称在哪里。详情AnsiPropertySource请见。

${application.title}

申请的标题,如中所述MANIFEST.MF。例如Implementation-Title: MyApp打印为MyApp

生成ASCII字符画的地址

  • http://patorjk.com/software/taag
  • http://www.network-science.de/ascii/
  • http://www.degraeve.com/img2txt.php

这里也有几个模板:  https://blog.csdn.net/ouyang_peng/article/details/51803181

就拿着里面的其中一个来演示:  banner.txt 文件

Spring Boot 2.x 系列--自定义banner_第3张图片

控制台打出的效果:

Spring Boot 2.x 系列--自定义banner_第4张图片

进阶玩法:  改变颜色输出

${AnsiColor.BRIGHT_RED}

Spring Boot 2.x 系列--自定义banner_第5张图片

 

自定义 banner 文件位置:  

application配置文件中使用 spring.banner.location 指定文件位置

如果文件的编码不是UTF-8,则可以进行设置spring.banner.charset

 

除了一个文本文件,你还可以添加一个banner.gifbanner.jpgbanner.png 图像文件到类路径或设置spring.banner.image.location属性。图像将转换为ASCII艺术表示,并打印在任何文本横幅上方。

 

开启关闭横幅配置  (配置文件优先级比编码方式高)

application配置方式

spring.main.banner-mode  (此配置为2.1.0, 有可能每个版本配置不一样.)

代码方式:  关闭横幅

    public static void main(String[] args) {
		//SpringApplication.run(BannerApplication.class, args);

		SpringApplication app = new SpringApplication(BannerApplication.class);
		app.setBannerMode(Banner.Mode.OFF);
		app.run(args);
	}

详细的就不写了,  就这样

 

 

你可能感兴趣的:(Spring,Boot,2.x)