Spring Boot 2.0(二):Spring Boot 2.0尝鲜-动态 Banner
2018-03-03 17:15
816 查看
Spring Boot 2.0 提供了很多新特性,其中就有一个小彩蛋:动态 Banner,今天我们就先拿这个来尝尝鲜。
设置完毕后,
Spring Boot 2.0 刚刚发布,一些 Maven 仓库还没更新,如果导入项目后依赖包不能下载,可以手动添加 Spring Boot 官方 Maven 仓库。
大家做好心理准备,第一次使用 Spring Boot 2.0 ,完整依赖包需要下载半小时左右。
一般情况下,我们会借助第三方工具帮忙转化内容,如网站
我们以Hello World为启动字符串来进行测试:
在 Spring Boot 2.0 项目
接下来在 Spring Boot 2.0 项目中测试打印动态 Banner ,使用的gif如下:
同样我们将 banner.gif 文件放到项目的
通过上述输出我们发现 Spring Boot 在启动的时候,会将 gif 图片的每一个画面,按照顺序打印在日志中,所有的画面打印完毕后,才会启动 Spring Boot 项目。
如果目录
项目的启动 Banner 有什么用呢,在一些大的组织或者公司中,可以利用这个特性定制自己专属的启动画面,增加团队对品牌的认同感。
示例代码-github
示例代码-码云
配置依赖
使用 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 有什么用呢,在一些大的组织或者公司中,可以利用这个特性定制自己专属的启动画面,增加团队对品牌的认同感。
示例代码-github
示例代码-码云
参考
demo-animated-banner相关文章推荐
- Spring Boot 2.0(二):Spring Boot 2.0尝鲜-动态 Banner
- Spring Boot 2.0(二):Spring Boot 2.0尝鲜-动态 Banner
- Spring boot 2.0 新特性之动态 Banner
- spring boot 2.0(二)动态banner的支持
- Spring Boot 2.0 动画Banner
- spring boot 2.0(一)权威发布spring boot2.0
- spring boot 集成quartz 2.0 实现前端动态配置(获取spring上下文)的两种方式,启动数据库中已开启定时任务
- Spring Boot 2.0(一):【重磅】Spring Boot 2.0权威发布
- Spring Boot教程(九)Spring Boot 1.5.x新特性:动态修改日志级别
- Spring Boot 2.0(八):Spring Boot 集成 Memcached
- spring boot 集成quartz 2.0 实现前端动态配置(获取spring上下文)的两种方式,启动数据库中已开启定时任务
- Spring Boot 2.0(六):使用 Docker 部署 Spring Boot 开源软件云收藏
- Spring Boot 2.0(六):使用 Docker 部署 Spring Boot 开源软件云收
- spring boot 2.0把spring boot data gemfire移除了
- Spring Boot 2.0(四):使用 Docker 部署 Spring Boot
- Spring Boot 2.0(四):使用 Docker 部署 Spring Boot
- spring boot 2.0,netty,mybatis,mysql,redis,docker 集成
- spring boot2.0 连接mysql ,自定义JpaRepository 分页, 封装jpa底层sql(二)
- 【springboot】Spring boot配置文件 application.properties
- spring boot框架学习9-spring boot的web开发(5)-错误解决及跳转页面