通过在 classpath 中添加banner.txt文件或将banner.location
在banner.txt文件中,您可以使用以下任何占位符:
表格 1_.横幅变量
| 变量 | 描述 |
|---|---|
${application.version} |
在MANIFEST.MF中声明的 application 的 version number。对于 example Implementation-Version: 1.0打印为1.0。 |
${application.formatted-version} |
在MANIFEST.MF中声明的 application 的 version number 用于显示(用括号括起来并以v为前缀)。对于 example (v1.0)。 |
${spring-boot.version} |
您正在使用的 Spring Boot version。对于 example 1.5.9.RELEASE。 |
${spring-boot.formatted-version} |
正在使用的 Spring Boot version 格式化显示(用括号括起来并以v为前缀)。对于 example (v1.5.9.RELEASE)。 |
${Ansi.NAME}(或${AnsiColor.NAME},${AnsiBackground.NAME},${AnsiStyle.NAME}) |
其中NAME是 ANSI 转义 code 的 name。有关详细信息,请参阅AnsiPropertySource。 |
${application.title} |
在MANIFEST.MF中声明的 application 的标题。对于 example Implementation-Title: MyApp打印为MyApp。 |
如果要以编程方式生成横幅,可以使用
SpringApplication.setBanner(…)方法。使用org.springframework.boot.Banner接口并实现自己的printBanner()方法。
您还可以使用spring.main.banner-mode property 来确定是否必须使用已配置的 logger(log)或根本不使用(off)在System.out(console)上打印横幅。
打印的横幅将在 name springBootBanner下注册为 singleton bean。
YAML maps
off到false所以如果要在 application 中禁用横幅,请务必添加引号。
spring:
main:
banner-mode: "off"
如果SpringApplication默认值不符合您的口味,您可以改为创建本地实例并对其进行自定义。例如,要关闭您要写的横幅:
public static void main(String[] args) { SpringApplication app = new SpringApplication(MySpringConfiguration.class); app.setBannerMode(Banner.Mode.OFF); app.run(args); }
传递给
SpringApplication的构造函数 arguments 是 spring beans 的 configuration 源。在大多数情况下,这些将是@Configurationclasses 的 references,但它们也可以是 XML configuration 或应扫描的包的 reference。
也可以使用application.properties文件配置SpringApplication
自定义Banner
application.properties
spring.banner.location=banner.txt
banner.txt
!
/^\
/ \
| | ( ) | |
/^\ | /^\ \ / /^\ | /^|O| /^\ ( )|-----|( ) /^\ |O|
|_| |-| |^-^|---||-----||---|^-^| |-| |_|
|O| |O| |/^\|/^\|| | ||/^\|/^\| |O| |O|
|-| |-| ||_|||_||| /^\ |||_|||_|| |-| |-|
|O| |O| |/^\|/^\||( )||/^\|/^\| |O| |O|
|-| |-| ||_|||_|||| ||||_|||_|| |-| |-|
启动
!
/^\
/ \
| | ( ) | |
/^\ | /^\ \ / /^\ | /^|O| /^\ ( )|-----|( ) /^\ |O|
|_| |-| |^-^|---||-----||---|^-^| |-| |_|
|O| |O| |/^\|/^\|| | ||/^\|/^\| |O| |O|
|-| |-| ||_|||_||| /^\ |||_|||_|| |-| |-|
|O| |O| |/^\|/^\||( )||/^\|/^\| |O| |O|
|-| |-| ||_|||_|||| ||||_|||_|| |-| |-|
2019-10-28 22:19:03.614 INFO 18192 --- [ main] com.example.demo.TestApplication : Starting TestApplication on WGR-PC with PID 18192 (E:\STSWorkspace\test\target\classes started by asus in E:\STSWorkspace\test)
2019-10-28 22:19:03.614 INFO 18192 --- [ main] com.example.demo.TestApplication : No active profile set, falling back to default profiles: default
2019-10-28 22:19:04.394 INFO 18192 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-10-28 22:19:04.432 INFO 18192 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
关闭Banner
spring.main.banner-mode=off
带枚举
更换Banner相对于隐藏要简单一些,我们只需要在src/main/resource下添加一个名叫banner.txt的文件,将需要修改的内容写入到该文件内就可以了,具体Banner内容如下所示:
${AnsiColor.BRIGHT_RED} ! 天地山青 ${AnsiColor.BRIGHT_YELLOW} !
${AnsiColor.BRIGHT_RED} /^\ ${AnsiColor.BRIGHT_YELLOW}道法无常 /^${AnsiColor.BRIGHT_RED} / \ 天地无极 ${AnsiColor.BRIGHT_YELLOW} / ${AnsiColor.BRIGHT_RED} | | ( ) | | ${AnsiColor.BRIGHT_YELLOW}乾坤戒法 | | ( ) | |
${AnsiColor.BRIGHT_RED} /^\ | /^\ \ / /^\ | /^\ 元阳入体 ${AnsiColor.BRIGHT_YELLOW} /^\ | /^\ \ / /^\ | /^${AnsiColor.BRIGHT_RED} |O| /^\ ( )|-----|( ) /^\ |O| ${AnsiColor.BRIGHT_YELLOW}五毒不侵 |O| /^\ ( )|-----|( ) /^\ |O|
${AnsiColor.BRIGHT_RED} |_| |-| |^-^|---||-----||---|^-^| |-| |_| 九阳之体 ${AnsiColor.BRIGHT_YELLOW} |_| |-| |^-^|---||-----||---|^-^| |-| |_|
${AnsiColor.BRIGHT_RED} |O| |O| |/^\|/^\|| | ||/^\|/^\| |O| |O| ${AnsiColor.BRIGHT_YELLOW}化缘神功 |O| |O| |/^\|/^\|| | ||/^\|/^\| |O| |O|
${AnsiColor.BRIGHT_RED} |-| |-| ||_|||_||| /^\ |||_|||_|| |-| |-| 邪魔退散 ${AnsiColor.BRIGHT_YELLOW} |-| |-| ||_|||_||| /^\ |||_|||_|| |-| |-|
${AnsiColor.BRIGHT_RED} |O| |O| |/^\|/^\||( )||/^\|/^\| |O| |O| ${AnsiColor.BRIGHT_YELLOW}永不宕机 |O| |O| |/^\|/^\||( )||/^\|/^\| |O| |O|
${AnsiColor.BRIGHT_RED} |-| |-| ||_|||_|||| ||||_|||_|| |-| |-| 永无八哥 ${AnsiColor.BRIGHT_YELLOW} |-| |-| ||_|||_|||| ||||_|||_|| |-| |-|
${AnsiColor.BRIGHT_CYAN}
在上面有一些属性配置,如${AnsiColor.BRIGHT_RED},这些配置都位于`org.springframework.boot.ansi.AnsiColor枚举内,用于配置的是输出的颜色。可配置内容如下所示:
DEFAULT("39"),
BLACK("30"),
RED("31"),
GREEN("32"),
YELLOW("33"),
BLUE("34"),
MAGENTA("35"),
CYAN("36"),
WHITE("37"),
BRIGHT_BLACK("90"),
BRIGHT_RED("91"),
BRIGHT_GREEN("92"),
BRIGHT_YELLOW("93"),
BRIGHT_BLUE("94"),
BRIGHT_MAGENTA("95"),
BRIGHT_CYAN("96"),
BRIGHT_WHITE("97");
这个配置是针对文字的颜色,当然还有背景颜色的配置,位于org.springframework.boot.ansi.AnsiBackground枚举内,可配置的内容如下所示:
DEFAULT("49"),
BLACK("40"),
RED("41"),
GREEN("42"),
YELLOW("43"),
BLUE("44"),
MAGENTA("45"),
CYAN("46"),
WHITE("47"),
BRIGHT_BLACK("100"),
BRIGHT_RED("101"),
BRIGHT_GREEN("102"),
BRIGHT_YELLOW("103"),
BRIGHT_BLUE("104"),
BRIGHT_MAGENTA("105"),
BRIGHT_CYAN("106"),
BRIGHT_WHITE("107");
具体的banner.txt的内容可根据自己的爱好进行配置
! 天地山青 !
/^\ 道法无常 /^ / \ 天地无极 / | | ( ) | | 乾坤戒法 | | ( ) | |
/^\ | /^\ \ / /^\ | /^\ 元阳入体 /^\ | /^\ \ / /^\ | /^ |O| /^\ ( )|-----|( ) /^\ |O| 五毒不侵 |O| /^\ ( )|-----|( ) /^\ |O|
|_| |-| |^-^|---||-----||---|^-^| |-| |_| 九阳之体 |_| |-| |^-^|---||-----||---|^-^| |-| |_|
|O| |O| |/^\|/^\|| | ||/^\|/^\| |O| |O| 化缘神功 |O| |O| |/^\|/^\|| | ||/^\|/^\| |O| |O|
|-| |-| ||_|||_||| /^\ |||_|||_|| |-| |-| 邪魔退散 |-| |-| ||_|||_||| /^\ |||_|||_|| |-| |-|
|O| |O| |/^\|/^\||( )||/^\|/^\| |O| |O| 永不宕机 |O| |O| |/^\|/^\||( )||/^\|/^\| |O| |O|
|-| |-| ||_|||_|||| ||||_|||_|| |-| |-| 永无八哥 |-| |-| ||_|||_|||| ||||_|||_|| |-| |-|
?
2019-10-28 22:26:50.213 INFO 18256 --- [ main] com.example.demo.TestApplication : Starting TestApplication on WGR-PC with PID 18256 (E:\STSWorkspace\test\target\classes started by asus in E:\STSWorkspace\test)
2019-10-28 22:26:50.215 INFO 18256 --- [ main] com.example.demo.TestApplication : No active profile set, falling back to default profiles: default
2019-10-28 22:26:51.140 INFO 18256 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-10-28 22:26:51.171 INFO 18256 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
原文:https://www.cnblogs.com/dalianpai/p/11756041.html