23.2 Customizing the Banner(定制Banner)
1 | The banner that is printed on start up can be changed by adding a |
当应用启动的时候显示的那个Banner是可以被放在类路径下的banner.txt所改变,或者通过设置spring.banner.location属性来指定bannner的位置。如果该banner文件的编码格式不是UTF-8,您可以通过设置spring.banner.charset来指定编码格式。除了text文件以外,您还可以指定一个banner.gif格式的文件,或者banner.jpg或者banner.png的图片文件到您类路径下,或者通过设置spring.banner.image.location属性来指定该图片位置。图片被转换成ASCII艺术表示并在上面打印任何文字横幅。1
Inside your banner.txt file, you can use any of the following placeholders:
在banner.txt文件中,您可以使用以下任何占位符:
| 属性 | 描述 |
|---|---|
| ${application.version} | 您应用的版本信息,诸如定义在MANIFEST.MF中的。举个例子,Implementation-Version: 1.0 则打印1.0. |
| ${application.formatted-version} | 同上,并且被格式化后显示 (用括号包围,并以v开头). 举个例子(v1.0). |
| ${spring-boot.version} | Spring Boot的版本。举个例子(v2.1.0.BUILD-SNAPSHOT). |
| ${spring-boot.formatted-version} | 同上,并且被格式化后显示(用括号包围,并以v开头). 举个例子 (v2.1.0.BUILD-SNAPSHOT). |
| ${Ansi.NAME} (or ${AnsiColor.NAME},${AnsiBackground.NAME}, ${AnsiStyle.NAME}) | 其中NAME是ANSI转义代码的名称,可以参考https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ansi/AnsiPropertySource.java |
| ${application.title} | 您的应用的标题,定义在MANIFEST.MF中。举个例子Implementation-Title: MyApp则打印“MyApp” |
1 | The SpringApplication.setBanner(… ) method can be used if you want |
如果需要,可以使用SpringApplication.setBanner(…)方法以编程方式生成横幅。使用org.springframework.boot.Banner接口实现您自己的printBanner()方法。1
2
3You can also use the spring.main.banner-mode property to determine if
the banner has to be printed on System.out (console), sent to the
configured logger (log), or not produced at all (off).
您也可以使用spring.main.banner-mode属性来确定是否横幅必须打印在System.out(控制台)上,发送到配置记录器(日志),或根本不生产(关闭)。1
2The printed banner is registered as a singleton bean under
the following name: springBootBanner.
打印banner被注册为一个名为“springBootBanner”的单例bean。1
2
3
4
5YAML maps off to false, so be sure to add quotes if you want to
disable the banner in your application, as shown in the following example:
spring:
main:
banner-mode: "off"
YAML映射“off”为“false”,因此如果您想在应用程序中禁用横幅,请务必添加引号。