springboot 自定义Banner

本文介绍如何在SpringBoot项目中控制logo的显示,包括关闭logo打印和自定义logo的方法。通过调整启动类或配置文件,可以轻松实现需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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的启动原理,这个还是值得研究的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值