Spring Boot -- 启动彩蛋

使用Spring Boot启动的jar包老是会显示一个Spring的图标:html

.   ____          _            __ _ _
/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/  ___)| |_)| | | | | || (_| |  ) ) ) )
'  |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::        (v1.3.3.RELEASE)

实际上Spring Boot在这个位置,放了一个彩蛋,咱们是能够自定义这个图标的。spring

咱们能够在resource目录下面放入一个banner.txt文件,Spring Boot启动项目的时候就会优先启动这个文件中的内容。api

这里给你们推荐两个个字符画生成的网站,咱们能够利用生成的字符串放入这个banner.txt文件:springboot

好比我生成一个star wars的图标:app

_______.___________.    ___      .______         
    /       |           |   /   \     |   _  \        
   |   (----`---|  |----`  /  ^  \    |  |_)  |       
    \   \       |  |      /  /_\  \   |      /        
.----)   |      |  |     /  _____  \  |  |\  \----.   
|_______/       |__|    /__/     \__\ | _| `._____|   
                                                      
____    __    ____  ___      .______          _______.
\   \  /  \  /   / /   \     |   _  \        /       |
 \   \/    \/   / /  ^  \    |  |_)  |      |   (----`
  \            / /  /_\  \   |      /        \   \    
   \    /\    / /  _____  \  |  |\  \----.----)   |   
    \__/  \__/ /__/     \__\ | _| `._____|_______/

这样启动的时候spring-boot

可是仅仅是这样看起来并很差看,还不如原来的图标好看呢。实际上Spring Boot为这个彩蛋提供了很多美化功能。网站

Spring Boot提供了一个枚举类AnsiColor,这个类能够控制banner.txt中的字符颜色,并且很是容易使用。.net

好比我能够将字符设置成颜色:BRIGHT_YELLOW3d

${AnsiColor.BRIGHT_YELLOW}
     _______.___________.    ___      .______         
    /       |           |   /   \     |   _  \        
   |   (----`---|  |----`  /  ^  \    |  |_)  |       
    \   \       |  |      /  /_\  \   |      /        
.----)   |      |  |     /  _____  \  |  |\  \----.   
|_______/       |__|    /__/     \__\ | _| `._____|   
                                                      
____    __    ____  ___      .______          _______.
\   \  /  \  /   / /   \     |   _  \        /       |
 \   \/    \/   / /  ^  \    |  |_)  |      |   (----`
  \            / /  /_\  \   |      /        \   \    
   \    /\    / /  _____  \  |  |\  \----.----)   |   
    \__/  \__/ /__/     \__\ | _| `._____|_______/

再从新启动项目,启动界面就会变成这个样子:code

相似 ${AnsiColor.BRIGHT_YELLOW} 这种表达式,其实能够放置多个,启动界面上的颜色,老是会根据AnsiColor的设置改变界面的颜色,这样启动的界面就会显示多种不一样的颜色了。

除了这样美化的功能以外,启动界面很重要的功能就是要告诉咱们这个项目的一些重要信息。

${application.version}                这个是MANIFEST.MF文件中的版本号  
${application.formatted-version} 这个是上面的的版本号前面加v后上括号  
${spring-boot.version}               这个是springboot的版本号  
${spring-boot.formatted-version}同上

把以上信息经过${}放入banner.txt中,就会打印出项目对应的信息。

这里放一个完整的demo:

${AnsiColor.BRIGHT_YELLOW}
     _______.___________.    ___      .______         ____    __    ____  ___      .______          _______.
    /       |           |   /   \     |   _  \        \   \  /  \  /   / /   \     |   _  \        /       |
   |   (----`---|  |----`  /  ^  \    |  |_)  |        \   \/    \/   / /  ^  \    |  |_)  |      |   (----`
    \   \       |  |      /  /_\  \   |      /          \            / /  /_\  \   |      /        \   \
.----)   |      |  |     /  _____  \  |  |\  \----.      \    /\    / /  _____  \  |  |\  \----.----)   |
|_______/       |__|    /__/     \__\ | _| `._____|       \__/  \__/ /__/     \__\ | _| `._____|_______/

${AnsiColor.BRIGHT_BLUE}
::: Project (version:${application.version}) :::             \(^O^)/    Spring-Boot ${spring-boot.version}

启动就会是这一个样子:

相关文章
相关标签/搜索