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 ...
随机推荐
- ansible-playbook 快速入门
管理用户密码: --- - hosts: test tasks: - name: changed password shell: echo root:123456 | chpasswd remote_ ...
- 超实用教程,教你用墨刀做出小红书app原型
一个新手怎么用1小时快速学会APP原型设计? 1小时很短,这意味着学习时必须把握APP原型设计中的重点.难点,而非面面俱到. 要在短时间内理解.掌握一个工具的使用,最有效的方式莫过于临摹: 看实例视频 ...
- 闪存卡被创建pv报错
背景:某机器有2块闪存卡,利用LVM,将其挂载到一个目录供测试使用: 之前厂商已经安装了闪存卡对应的驱动,fdisk可以看到闪存卡信息,但是在pvcreate创建时,遭遇如下错误: # pvcreat ...
- python爬虫-基础入门-爬取整个网站《2》
python爬虫-基础入门-爬取整个网站<2> 描述: 开场白已在<python爬虫-基础入门-爬取整个网站<1>>中描述过了,这里不在描述,只附上 python3 ...
- windows Server2012 IIS8.0配置安装完整教程
IIS8.0是windows Server2012自带的服务器管理系统,和以往不同,IIS8.0安装和操作都比较简单,界面很简洁,安装也很迅速.今天我们重点完整的演示下Internet Informa ...
- python遍历某一位置所有文件夹中的文件
通过多次遍历达到找出所有文件的目的 import os rootdir=["d:/77"] c=[] for i in rootdir: for parent,dirnames,f ...
- git时光机操作
A状态:代码版本A B状态:代码版本B(比A状态时增加了图片.代码) 这时,git add. git commit -m"" .push之前,意识到忘了让git忽略图片的添加,就: ...
- scu 4439 Vertex Cover
题意: 给出n个点,m条边,将若干个点染色,使得每个边至少有一点染色,问至少染多少个点. 思路: 如果是二分图,那就是最小点覆盖,但是这是一般图. 一般图的最小覆盖是npc问题,但是这题有一个条件比较 ...
- 如何用新安装的jdk替换掉Linux系统默认jdk
版主写的非常棒: http://blog.csdn.net/u011364306/article/details/48375653
- 字符编码几个缩写 ACR CCS CEF CES TES
摘自https://zhuanlan.zhihu.com/p/27012967 5. 在Unicode Technical Report (UTR统一码技术报告) #17<UNICODE CHA ...