Springboot项目启动之后会打印一个默认logo,如果我们不想在项目启动的时候打印这个logo后者想自定义logo,这都可以实现
一、关闭logo打印
(1) 可以通过在启动类的main方法中设置banner的mode,其中Mode为一个枚举值,有OFF、CONSOLE、LOG三个值可选
SpringApplication application = new SpringApplication(Application.class);
application.setBannerMode(Banner.Mode.OFF);
(2) 在配置文件中进行配置
spring:
main:
banner-mode: OFF
二、自定义banner
springboot 2.0以前的版本可以通过直接在src/main/source/目录下定义banner.txt文件,在文件中写入想要打印的内容,springboot项目在启动的时候会自动读取该文件进行输出
springboot 2.0之后除了可以自动读取src/main/source/目录下自定义banner.txt文件外,还可以通过配置文件指定logo文件的位置及名字,以及相关配置,具体可参考参观文档
# BANNER
spring.banner.charset=UTF-8 # Banner file encoding.
spring.banner.location=classpath:banner.txt # Banner text resource location.
spring.banner.image.location=classpath:banner.gif # Banner image file location (jpg or png can also be
used).
spring.banner.image.width=76 # Width of the banner image in chars.
spring.banner.image.height= # Height of the banner image in chars (default based on image height).
spring.banner.image.margin=2 # Left hand image margin in chars.
spring.banner.image.invert=false # Whether images should be inverted for dark terminal themes.
此外在自定义banner中还可以进行一些属性设置
${AnsiColor.BRIGHT_RED}设置控制台中输出内容的颜色
${application.version}用来获取MANIFEST.MF文件中的版本号
${application.formatted-version}格式化后的
${application.version}版本信息
${spring-boot.version}Spring Boot的版本号
${spring-boot.formatted-version}格式化后的
${spring-boot.version}版本信息
...
花太多的时间研究打印出一个漂亮的banner,必须性不太大,通过springboot对banner的输出探究springboot的启动原理,这个还是值得研究的。