Spring Boot笔记之自定义启动banner

控制banner内容

Spring Boot启动的时候默认的banner是spring的字样,看多了觉得挺单调的,Spring Boot为我们提供了自定义banner的功能。

自定义banner只需要在resource下新建一个banner.txt文件,将我们需要的banner字样放进去,启动的时候就会去读取使用这个文本文件中的banner。

比如:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
                    _ooOoo_
                   o8888888o
                   88" . "88
                   (| -_- |)
                   O\  =  /O
                ____/`---'\____
              .'  \\|     |//  `.
             /  \\|||  :  |||//  \
            /  _||||| -:- |||||-  \
            |   | \\\  -  /// |   |
            | \_|  ''\---/''  |   |
            \  .-\__  `-`  ___/-. /
          ___`. .'  /--.--\  `. . __
       ."" '<  `.___\_<|>_/___.'  >'"".
      | | :  `- \`.;`\ _ /`;.`/ - ` : | |
      \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                    `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          佛祖保佑       永无BUG

控制banner样式

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

AnsiColor: 用来设定字符的前景色

AnsiBackground: 用来设定字符的背景色

AnsiStyle: 用来控制加粗、斜体、下划线等等。

 

使用${AnsiFoo.Bar}来指定样式,当指定样式的时候会有提示的:

image 

指定一种试一下,比如下面这种:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
${AnsiColor.BRIGHT_YELLOW}
                    _ooOoo_
                   o8888888o
                   88" . "88
                   (| -_- |)
                   O\  =  /O
                ____/`---'\____
              .'  \\|     |//  `.
             /  \\|||  :  |||//  \
            /  _||||| -:- |||||-  \
            |   | \\\  -  /// |   |
            | \_|  ''\---/''  |   |
            \  .-\__  `-`  ___/-. /
          ___`. .'  /--.--\  `. . __
       ."" '<  `.___\_<|>_/___.'  >'"".
      | | :  `- \`.;`\ _ /`;.`/ - ` : | |
      \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                    `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          佛祖保佑       永无BUG

效果:

 image
嗯,背景色的原因好丑啊….不过重点不是这个。

重点是这个颜色的设置是可以变的,也就是说同一个屏幕可以指定多个 {AnsiColor.FooColor}这种,指定了颜色之后直到下次指定之前的字符都是FooColor颜色的,一个简单的例子,来将大佛的疙瘩设置为不同的颜色(为什毛我感觉下面的这段字符很搞笑,起风了...):</p><div><div id="highlighter_241032" class="syntaxhighlighter  text"><div class="toolbar"><span><a href="#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="text plain"> {AnsiColor.BRIGHT_YELLOW}

                    ${AnsiColor.BRIGHT_RED}_ooOoo_${AnsiColor.BRIGHT_YELLOW}
                   ${AnsiColor.BRIGHT_RED}o8888888o${AnsiColor.BRIGHT_YELLOW}
                   ${AnsiColor.BRIGHT_RED}88${AnsiColor.BRIGHT_YELLOW}" . "${AnsiColor.BRIGHT_RED}88${AnsiColor.BRIGHT_YELLOW}
                   (| -_- |)
                   O\  =  /O
                ____/`---'\____
              .'  \\|     |//  `.
             /  \\|||  :  |||//  \
            /  _||||| -:- |||||-  \
            |   | \\\  -  /// |   |
            | \_|  ''\---/''  |   |
            \  .-\__  `-`  ___/-. /
          ___`. .'  /--.--\  `. . __
       ."" '<  `.___\_<|>_/___.'  >'"".
      | | :  `- \`.;`\ _ /`;.`/ - ` : | |
      \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                    `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          佛祖保佑       永无BUG

效果:

image

显示应用信息

除了上面的指定样式之外,还可以显示一些与应用相关的版本信息:

${application.version}   与MANIFEST.MF文件中相同的版本号,比如1.5.4.RELEASE

${application.formatted-version}   格式化过的版本号就是加个v然后用括号包起来,比如(v1.5.4.RELEASE)

${application.title} 

${spring-boot.version} Spring Boot的版本

${spring-boot.formatted-version} 格式化过的版本

控制banner是否开启,输出位置

设置banner mode为OFF关闭banner:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package org.cc11001100;
 
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
@SpringBootApplication
public class SpringBootStudy002Application {
 
     public static void main(String[] args) {
         SpringApplication springApplication = new SpringApplication(SpringBootStudy002Application. class );
         springApplication.setBannerMode(Banner.Mode.OFF);
         springApplication.run(args);
     }
 
}

 

几个常用的字符画生成网站

介绍几个常用的字符画生成网站:

1. http://patorjk.com/software/taag/#p=display&f=Henry%203D&t=CC11001100%0A 这个是比较常用的,可以根据输入的字符生成字符画

image

2. https://spring-boot-banner-gen.cfapps.io/ 可以将上传图片转为文本形式的字符画,只是感觉风格比较鬼畜(绝不能承认是我长的鬼畜…),这是鄙人的字符画….

image

3. http://www.degraeve.com/img2txt.php 可以根据在线的图片网址生成字符画,比如可以直接将公司logo的地址粘贴进去生成字符画,风格还算正常…

来张祖师爷的画像:

image

 

.

4
0
currentDiggType = 0;
« 上一篇: Windows Live Writer博客草稿迁移的一种解决方案
» 下一篇: Redis笔记之常用命令
posted @ 2017-08-31 00:09 CC11001100 阅读( 8496) 评论( 0) 编辑 收藏
qcloud0702
fixPostBody(); setTimeout(function () { incrementViewCount(cb_entryId); }, 50); deliverAdT2(); deliverAdC1(); deliverAdC2(); loadNewsAndKb(); loadBlogSignature(); LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid); GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate, cb_postType); loadOptUnderPost(); GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);

</div><!--end: forFlow -->
</div>

猜你喜欢

转载自blog.csdn.net/u012343297/article/details/80974610