Java学习-086-Springboot 自定义启动 banner 信息

Springboot 启动时会加载默认的 banner 信息,并在控制台输出。因而可以通过自定义 banner 文件内容实现启动 banner 的自定义。

在项目的 resouces 目录下新增 banner.txt 文件,输入以下内容并保存。

 .----------------.  .----------------.  .----------------.  .----------------.  .----------------.  .----------------.
| .--------------. || .--------------. || .--------------. || .--------------. || .--------------. || .--------------. |
| |     _____    | || |      __      | || |     ______   | || |     ____     | || |     ______   | || |     ____     | |
| |    |_   _|   | || |     /  \     | || |   .' ___  |  | || |   .'    `.   | || |   .' ___  |  | || |   .'    `.   | |
| |      | |     | || |    / /\ \    | || |  / .'   \_|  | || |  /  .--.  \  | || |  / .'   \_|  | || |  /  .--.  \  | |
| |   _  | |     | || |   / ____ \   | || |  | |         | || |  | |    | |  | || |  | |         | || |  | |    | |  | |
| |  | |_' |     | || | _/ /    \ \_ | || |  \ `.___.'\  | || |  \  `--'  /  | || |  \ `.___.'\  | || |  \  `--'  /  | |
| |  `.___.'     | || ||____|  |____|| || |   `._____.'  | || |   `.____.'   | || |   `._____.'  | || |   `.____.'   | |
| |              | || |              | || |              | || |              | || |              | || |              | |
| '--------------' || '--------------' || '--------------' || '--------------' || '--------------' || '--------------' |
 '----------------'  '----------------'  '----------------'  '----------------'  '----------------'  '----------------'

 

 

重新启动 springboot 项目,banner 信息显示如下

 

同时,banner.txt 文件中也可引用 application.properties 中的变量,引用方式 ${变量名}。

在 banner.txt 文件中添加如下信息:

CurrentApp Version:${version.app}
Springboot Version:${version.springboot}

 

同时在  application.properties 添加变量信息

version.app=1.0.0
version.springboot=2.6.3

 

重新 springboot 服务,控制台输出如下,说明变量被成功引用。

 

附录:

banner 在线生成工具:

https://www.bootschool.net/ascii

http://patorjk.com/software/taag/

 

posted @ 2022-02-19 17:27  范丰平  Views(514)  Comments(0Edit  收藏  举报