3

一步为你的Springboot应用自定义banner

 3 years ago
source link: https://segmentfault.com/a/1190000038855168
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

这个小功能据说是Springboot2.x的小彩蛋,出来很久很久了。之前知道没试过,这次试了一下,还可以,挺好玩的。最近因为开始重新看Springboot,看到了这个部分,于是整理到了文章中。烂大街的东西,拿来丢人显眼了。

什么是banner?

就是这个默认的Spring标识,有时候看着太难看,所以想换换,没什么卵用,有时候还会使你的Springboot应用启动变慢。所以看着玩玩就好。

看好了,在你的springboot项目的resource目录下,新建一个banner.txt文件,你在里面写的内容就是要显示的内容。

比如说我们写上:愚公要移山。

这样写起来比较难看。还不如以前的格式好看,不过没关系,也有一些好看的网站已经帮我们实现了。转化之后把内容替换掉就可以。

使用一张地图试试

效果如下:

具体的你自己琢磨吧。

还是难看?没事接着看

这颜色太难看了。没事,还有配置。

Spring提供了三个枚举类来设定字符的颜色,分别是:

  • AnsiColor: 用来设定字符的前景色
  • AnsiBackground: 用来设定字符的背景色
  • AnsiStyle: 用来控制加粗、斜体、下划线等等。

我们设置个颜色试试。

最后启动,看看效果

小玩意,东西虽好,不要贪用!!感谢


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK