23.2 Customizing the Banner
在程序启动时打印的横幅可以通过在类路径添加banner.txt
或者通过设置spring.banner.location
属性路径下的文件配置.如果文件不打算使用utf-8
编码,你可以通过spring.banner.charset
属性设置.
除了文本文件,您还可以添加banner.gif
,banner.jpg
或banner.png
图像文件到您的类路径或设置spring.banner.image.location
位置指定.图像文件会被转换成ASCII艺术表现并会在文字上面打印出来.
在你的banner.txt文件中,您可以使用以下任何一个占位符: Table23.1 Banner variables
Variable | Description |
---|---|
${application.version} | 程序版本号,在MANIFEST.MF文件中定义.例如:Implementation-Version: 1.0 打印出1.0. |
${application.formatted-version} | 程序版本号,在MANIFEST.MF文件中定义且格式化显示(带前缀v以及括号括起来),例如(v1.0). |
${spring-boot.version} | 正在使用的Spring Boot版本,例如v2.0.2.RELEASE |
${spring-boot.formatted-version} | 正在使用的Spring Boot版本,格式化显示(带前缀v以及括号括起来),例如(v2.0.2.RELEASE) |
${Ansi.NAME}(or ${AnsiColor.NAME},${AnsiBackgroud.NAME},${AnsiStyle.NAME}) | Name为ANSI转移码名.具体请查看AnsiPropertySource |
${application.title} | 程序标题,在MANIFEST.MF文件中定义.例如:Implementation-Title: MyApp 打印出MyApp. |
Tip
如果你想以编程方式生成一个横幅,可以使用
SpringApplication.setBanner(…)
方法.实现org.springframework.boot.Banner
接口并覆盖你自己的printBanner()方法.
你也可以使用spring.main.banner-mode
属性来确定横幅打印选项.输出至System.out
(console
),发送到配置日志记录器(log
),或者根本不生成(off
).
横幅输出被注册为一个单实例,名称为:springBootBanner
.
Note
YAML 映射
off
为false
,所以在你的配置文件中配置禁止横幅输出时(配置off)时记得一定要加引号,如以下示例所示:
spring:
main:
banner-mode: "off"