温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何修改SpringBoot项目启动banner

发布时间:2021-07-02 14:20:00 来源:亿速云 阅读:280 作者:小新 栏目:编程语言

小编给大家分享一下如何修改SpringBoot项目启动banner,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

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

如何修改SpringBoot项目启动banner

查看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会出现下面提示,正对应上面翻译的内容。

如何修改SpringBoot项目启动banner

1、自定义banner

我们在类路径下新建banner.txt文件,绘制下面图案,下面地址就是绘制字符图案。
http://patorjk.com/software/taag/

如何修改SpringBoot项目启动banner

SpringBoot项目启动后如下,这样我们就修改了banner。

如何修改SpringBoot项目启动banner

我们暂时删除banner.txt文件,将下面图片放置在类路径下,名称为:banner.jpg。

如何修改SpringBoot项目启动banner

然后在配置文件中配置如下内容

如何修改SpringBoot项目启动banner

启动SpringBoot项目后,图案如下所示,Springboot把图片转成 ASCII图案。

如何修改SpringBoot项目启动banner

如果我们不想在启动时出现图案,那么就需要修改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启动时就不会打印图案了。

以上是“如何修改SpringBoot项目启动banner”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI