Spring Boot 2 (二):Spring Boot 2 尝鲜-动态 Banner
Spring Boot 2.0 提供了很多新特性,其中就有一个小彩蛋:动态 Banner,今天我们就先拿这个来尝尝鲜。
配置依赖
使用 Spring Boot 2.0 首先需要将项目依赖包替换为刚刚发布的 2.0 RELEASE,现在网站https://start.spring.io/也将 Spring Boot 2.0 设置为默认版本。
<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>2.0.0.RELEASE</version>
</parent>
设置完毕后,dependencies中没有指明版本的依赖包,将自动使用2.0.0.RELEASE依赖的版本。
<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter</artifactId>
	</dependency>
</dependencies>
Spring Boot 2.0 刚刚发布,一些 Maven 仓库还没更新,如果导入项目后依赖包不能下载,可以手动添加 Spring Boot 官方 Maven 仓库。
<repositories>
	<repository>
		<id>spring-milestones</id>
		<name>Spring Milestones</name>
		<url>https://repo.spring.io/libs-milestone</url>
		<snapshots>
			<enabled>false</enabled>
		</snapshots>
	</repository>
</repositories>
大家做好心理准备,第一次使用 Spring Boot 2.0 ,完整依赖包需要下载半小时左右。
Spring Boot 更换 Banner
我们先来回顾一下在 Spring Boot 1.0 中如何更换启动 Banner,其实都很简单,只需要在src/main/resources路径下新建一个banner.txt文件,banner.txt中填写好需要打印的字符串内容即可。
一般情况下,我们会借助第三方工具帮忙转化内容,如网站http://www.network-science.de/ascii/将文字转化成字符串,网站:http://www.degraeve.com/img2txt.php可以将图片转化成字符串。

我们以Hello World为启动字符串来进行测试:
.__           .__  .__                               .__       .___
|  |__   ____ |  | |  |   ____   __  _  _____________|  |    __| _/
|  |  \_/ __ \|  | |  |  /  _ \  \ \/ \/ /  _ \_  __ \  |   / __ |
|   Y  \  ___/|  |_|  |_(  <_> )  \     (  <_> )  | \/  |__/ /_/ |
|___|  /\___  >____/____/\____/    \/\_/ \____/|__|  |____/\____ |
     \/     \/                                                  \/
在 Spring Boot 2.0 项目src/main/resources路径下新建一个banner.txt文件,粘贴上述字符串,启动 Spring Boot 项目观察启动日志,发现 Spring Boot 2.0 已经将默认的 Spring 字符串替换为 hello world。说明 Spring Boot 2.0 也支持1.0更换 Banner 的方法。
接下来在 Spring Boot 2.0 项目中测试打印动态 Banner ,使用的gif如下:

同样我们将 banner.gif 文件放到项目的src/main/resources路径下,启动项目进行测试,输出栏打印信息如下:
                                        ..
                                       .::*
                                        ...                                   
  .....                                                             ....
  ........                                                            .    ...
  ........                                                                . ..
  ......                                                                  ....
  ....                                                                     ...
  .                                                                          .
                                    ..**::**..
                                  .*::::::::::*.
                                 .*::::::::::::*.
                                 .*::::::::::::*.
                                 .*::::::::::::*.
                                  .*::::::::::*.
                                    ..**::***.                                
  ..
  .....                                                                     ..
  .....                                                                    ...
  ......                                                                ......
  . ...    .                                                             .....
  .       ....                                                             . .
                ............................   .............
              .................. .........       ................    .
          ...................                   ... . ... ............
       .............   . ...                             ...............
      .   .........                                         ...........
         ..........                                            ....... ....
        ............                                                ........
        ........                                                     ........
      .... .                                                        .........
     ........                                                        ........
   .........                       ..********..                      ......*..
  ........                      .**::::::::::::**.                    ........
  ...........                 .**::::::::::::::::**.                   .......
  ......                     .*::::::::::::::::::::*.                  .......
  ... ..                    .*::::::::::::::::::::::*.                 .......
  ......                    .::::::::::::::::::::::::.                 .......
  ..........                .::::::::::::::::::::::::.                ... ....
  .........                 .*:::::::::::::::::::::::.                    ....
  .........                 .*::::::::::::::::::::::*.                     ...
  .........                  .*::::::::::::::::::::*.                     ....
   ........                   .**::::::::::::::::**.                 .........
    ... ....                    .**::::::::::::**.                   .........
  . ........                        .********..                      .........
     ....... .                                                      ......*..
     .........                                                     .   .....
      .......                                                    .........
      ........     .                                          ............
      ............  ..                                        ...........
        . .............                                        .........
         ................                              ....   ..........
           ............. ....    .                   ......... . ..... .
            .... ...... .........       . .. .... .............. ....
              ..       .............  ...........  ..............             
                                ::.        .*:*
                             :.        *:*      *. .*:*
                          .:*.    *:   .*:*.       :.   .:
                      :* :     :.                .::::*    :
                    :  :    *         *****.....       *.:   :
                  :   : .:*         .::::::::::**..     ..  : *
                 :   *:           .*:::::::::::::::*.     *   **
                o  ***        ...**::::::::::::::::::**.   *   :.:
               : .* :    .....***::::::::::::::::::::::*.   :   : o
               :*.  *   ..*****:::::::::::::::::::::::::*.   *  :  o
               :   .   .*::::::::::::::::::::::::::::::::*.    ::   *
              :*   :   *::::::::::::::::::::::::::::::::::*     :   o
             * o  *   .*::::::::::::::::::::::::::::::::::*.   .:o  :
             :  : :   .*::::::::::::::::::::::::::::::::::*.   :  . :
             :  ..    .*::::::::::::::::::::::::::::::::::*.   *  : *
             :   :    .*::::::::::::::::::::::::::::::::::*   :   *:
             .   :*    .*o:::::::::::::::::::::::::::::::*.   .   :
              :  :  *   .*::::::::::::::::::::::::::::::*.   *   :*
               o *   :   .*::::::::::::::::::::::::::::*.    : ** :
                 :*   *    .*::::::::::::::::::::::::**.    *..  *
                  **   *    ..*::::::::::::::::::::*..     :*   *
                   * o  ..     ..**::::::::::::**..    .:. :   :
                    :   o.:        ...******...      *.   :  :.
                      :     ::o:.                *:     * *:
                        :.    :       .*:*.   :*    .*::
                           .:*  .*      *o:        .:
                                   .:*.        .*:                                          
        ...                                                                      
通过上述输出我们发现 Spring Boot 在启动的时候,会将 gif 图片的每一个画面,按照顺序打印在日志中,所有的画面打印完毕后,才会启动 Spring Boot 项目。
如果目录src/main/resources下同时存在banner.txt和banner.gif,项目会先将banner.gif每一个画面打印完毕之后,再打印banner.txt中的内容。
项目的启动 Banner 有什么用呢,在一些大的组织或者公司中,可以利用这个特性定制自己专属的启动画面,增加团队对品牌的认同感。
Spring Boot 2 (二):Spring Boot 2 尝鲜-动态 Banner的更多相关文章
- Spring Boot 2.0(二):Spring Boot 2.0尝鲜-动态 Banner
		
Spring Boot 2.0 提供了很多新特性,其中就有一个小彩蛋:动态 Banner,今天我们就先拿这个来尝尝鲜. 配置依赖 使用 Spring Boot 2.0 首先需要将项目依赖包替换为刚刚发 ...
 - (转)Spring Boot 2 (二):Spring Boot 2 尝鲜-动态 Banner
		
http://www.ityouknow.com/springboot/2018/03/03/spring-boot-banner.html Spring Boot 2.0 提供了很多新特性,其中就有 ...
 - Spring Boot 2.0尝鲜-动态 Banner
		
配置依赖 使用 Spring Boot 2.0 首先需要将项目依赖包替换为刚刚发布的 2.0 RELEASE,现在网站https://start.spring.io/也将 Spring Boot 2. ...
 - Spring Boot 2.0(一):Spring Boot 2.0尝鲜-动态 Banner
		
Spring Boot 2.0 提供了很多新特性,其中就有一个小彩蛋:动态 Banner,今天我们就先拿这个来尝尝鲜 Spring Boot 更换 Banner 我们先来回顾一下在 Spring Bo ...
 - Spring Boot系列二 Spring @Async异步线程池用法总结
		
1. TaskExecutor Spring异步线程池的接口类,其实质是java.util.concurrent.Executor Spring 已经实现的异常线程池: 1. SimpleAsyncT ...
 - <Spring Data JPA>二 Spring Data Jpa
		
1.pom依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...
 - Spring boot 入门二:Spring Boot配置文件详解
		
一.自定义属性 当我们创建一个springboot项目的时候,系统默认会为我们在src/main/java/resources目录下创建一个application.properties.同时也支持ym ...
 - spring boot 学习(二)spring boot 框架整合 thymeleaf
		
spring boot 框架整合 thymeleaf spring boot 的官方文档中建议开发者使用模板引擎,避免使用 JSP.因为若一定要使用 JSP 将无法使用. 注意:本文主要参考学习了大神 ...
 - Spring Boot系列(二) Spring Boot 之 REST
		
Rest (Representational Stat Transer) 是一种软件架构风格. 基础理论 架构特性 性能 可伸缩 简化的统一接口 按需修改 组件通信透明 可移植 可靠性 架构约束 C/ ...
 
随机推荐
- SS上网配置(Window 7/8/10 )详解
			
SS很多人都会用到,尤其是做外贸的朋友,今天我们来说下SS相关的配置. 首先从官网下载解压后的目录如结构下:  点击***.exe,选择以管理员身份运行,切记打开后界面如下  服务器地址为一段I ...
 - Noip2014生活大爆炸版石头剪刀布【水模拟】
			
模拟暴力也要优雅. https://www.luogu.org/problemnew/show/P1328 像我这种蒟蒻就会敲无数个ifelse qaq. 可以优雅地进行预处理一下. 膜法真是好东西q ...
 - 《windows核心编程系列》一谈谈windows中的错误处理机制
			
错误处理 我们写的函数会用返回值表示程序执行的正确与否,使用void,就意味着程序一定不会出错.Bool类型标识true时为真,false时为假.其他类型根据需要可以定义成不同意义. Windows除 ...
 - jenkins一次构建两次触发job问题
			
具体内容详见: https://issues.jenkins-ci.org/browse/JENKINS-21464?focusedCommentId=250183&page=com.atla ...
 - [ZOJ1610]Count the Colors
			
Description 画一些颜色段在一行上,一些较早的颜色就会被后来的颜色覆盖了. 你的任务就是要数出你随后能看到的不同颜色的段的数目. Input 每组测试数据第一行只有一个整数n, 1 < ...
 - 417 Pacific Atlantic Water Flow 太平洋大西洋水流
			
详见:https://leetcode.com/problems/pacific-atlantic-water-flow/description/ C++: class Solution { publ ...
 - jquery readio checked
			
今天太鬼火了为这个难问题搜了一下午了到最后还是csdn的朋友给了我正确的答案http://bbs.csdn.net/topics/300162450谢谢这位朋友 // $("#ISOK1&q ...
 - js的replace函数把"$"替换成成"\$"
			
var aa = 18$ 转换成 aa = 18\$ aa.replace("\$","\\\$"); 注意JS的replace方法只能替换第一 ...
 - 冒泡排序算法和简单选择排序算法的js实现
			
之前已经介绍过冒泡排序算法和简单选择排序算法和原理,现在有Js实现. 冒泡排序算法 let dat=[5, 8, 10, 3, 2, 18, 17, 9]; function bubbleSort(d ...
 - InChatter系统之客户端实现原理与阶段小结
			
InChatter客户端的开发可以说是目前系统的阶段性结尾了.很抱歉的是,这篇文章来的这么晚,迟到了这么久. 在客户端的开发主要针对两个方面: 消息的传输与处理 消息的UI交互处理 一.消息的传输与处 ...