修改SpringBoot项目的启动banner(超个性)

如果我们使用过SpringBoot,那么就会对下面的图案不陌生。Springboot 启动的同时会打印下面的图案,并带有版本号。
在这里插入图片描述

查看SpringBoot官方文档可以找到关于 banner 的描述

The banner that is printed on start up can be changed by adding a banner.txt file to your classpath or by setting the spring.banner.location property to the location of such a file. If the file has an encoding other than UTF-8, you can set spring.banner.charset. In addition to a text file, you can also add a banner.gif, banner.jpg, or banner.png image file to your classpath or set the spring.banner.image.location property. Images are converted into an ASCII art representation and printed above any text banner.


通过有道翻译


可以通过向类路径中添加一个banner.txt文件或设置spring.banner来更改在console上打印的banner。属性指向此类文件的位置。如果文件的编码不是UTF-8,那么可以设置spring.banner.charset。除了文本文件,还可以添加横幅。将gif、banner.jpg或banner.png图像文件保存到类路径或设置spring.banner.image。位置属性。图像被转换成ASCII艺术形式,并打印在任何文本横幅上面。

在IDEA中,在SpringBoot配置文件中输入spring.banner会出现下面提示,正对应上面翻译的内容。
在这里插入图片描述

1、自定义banner

我们在类路径下新建banner.txt文件,绘制下面图案,下面地址就是绘制字符图案。
http://patorjk.com/software/taag/#p=display&f=Graffiti&t=XXXQ
在这里插入图片描述
SpringBoot项目启动后如下,这样我们就修改了banner。
在这里插入图片描述
我们暂时删除banner.txt文件,将下面图片放置在类路径下,名称为:banner.jpg。
在这里插入图片描述
然后在配置文件中配置如下内容
在这里插入图片描述
启动SpringBoot项目后,图案如下所示,Springboot把图片转成 ASCII图案。
在这里插入图片描述
如果我们不想在启动时出现图案,那么就需要修改SpringBoot启动类的代码

原代码

public static void main(String[] args) {
    SpringApplication.run(SpringbootShiroApplication.class, args);
}

修改后的代码

public static void main(String[] args) {
    SpringApplication app = new SpringApplication(SpringbootShiroApplication.class);
    app.setBannerMode(Banner.Mode.OFF);
    app.run(args);
}

这样,SpringBoot启动时就不会打印图案了。
当然,还有其他的方式改变以及关闭启动的图案,如果大家有不一样的方式,可以在下方评论来说明。

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值