Spring Boot 2 (二):Spring Boot 2 动态 Banner
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系列二 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/ ...
- Spring学习(二)—— java的动态代理机制
在学习Spring的时候,我们知道Spring主要有两大思想,一个是IoC,另一个就是AOP,对于IoC,依赖注入就不用多说了,而对于Spring的核心AOP来说,我们不但要知道怎么通过AOP来满足的 ...
- Spring学习(十二)-----Spring @PostConstruct和@PreDestroy实例
实现 初始化方法和销毁方法3种方式: 实现标识接口 InitializingBean,DisposableBean(不推荐使用,耦合性太高) 设置bean属性 Init-method destroy- ...
- Spring学习(十二)-----Spring Bean init-method 和 destroy-method实例
实现 初始化方法和销毁方法3种方式: 实现标识接口 InitializingBean,DisposableBean(不推荐使用,耦合性太高) 设置bean属性 Init-method destroy- ...
- spring学习笔记二:spring使用构造方法注入(set方式注入)
项目目录树: 1.spring的依赖包配置 * SPRING_HOME/dist/spring.jar * SPRING_HOME/lib/log4j/log4j-1.2.14.jar * SPRIN ...
随机推荐
- API 接口自动化测试框架
转自: https://testerhome.com/topics/3455 前言 接口自动化逐渐成为各大公司投入产出最高的测试技术.但是如何在版本迅速迭代过程中提高接口自动化的测试效率,仍然是大部分 ...
- histogram 和 bar plot的区别
最本质的区别是这样的:histogram用来描述的是numerical变量,而bar plot用来描述的是categorical类型的变量.统计学当中关于变量的分类 这可以从它们的图形上面看到: hi ...
- 移动端--touch事件与点透问题
也来说说touch事件与点击穿透问题: http://blog.csdn.net/alex8046/article/details/52299785
- _proto_ 和prototype自己的理解
对象(obj)并不具有prototype属性,只有函数(function)才有prototype属性 1.在JS里,万物皆对象. 方法(Function)是对象,方法的原型(Function.prot ...
- cocos2dx 3.x 网络循环接收数据(RakNet::Packet* packet)单步网络接收
void FriendFightLayer::update(float dt) { dealWithPacket(dt); if (m_isNeedSwitchToLobby) { PublicMet ...
- Linux 重启nginx
重启 1.验证nginx配置文件是否正确 方法一:进入nginx安装目录sbin下,输入命令./nginx -t 看到如下显示nginx.conf syntax is ok nginx.conf te ...
- BCB Access violateion at Address 0000 0003. Read of address 0000 0003
来自网页:(我的电脑做不到) 运行一个程序,莫名出现一个对话框:access violation at address 0000.. read of address000试了几次问题依旧,网上搜了下解 ...
- 从caffemodel里面导出参数
参见博文https://blog.csdn.net/u014510375/article/details/51704447
- [13]Windows 内核情景分析 --- 网络通信
典型的基于tcpip协议套接字方式的网络通信模块层次: 应用程序 socket api WS2_32.dll socket irp Afd.sys tdi irp Tcpip.sys 回调函数接口 各 ...
- JavaScript(四):运算符&数据类型转换
+:算符的加法:连接字符串 加法会将其它类型的值,自动转为字符串,然后再进行连接运算! var a=1+2; console.log('first: '+a); var a=1+2+'3';//先计算 ...