【SpringBoot系列】三、SpringBoot特性_SpringApplication类(自定义Banner)

    SpringApplication类作为SpringBoot最基本、最核心的类,在main方法中用来启动SpringBoot项目。一般情况下,只需在main方法中使用SpringApplication.run静态方法来启动项目:

package com.xcbeyond.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
 * SpringBoot启动类
 * @author xcbeyond
 * 2018年7月2日下午5:41:45
 */
@SpringBootApplication
public class SpringbootApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringbootApplication.class, args);
	}
} 

关于SpringApplication有以下常用特性:

自定义启动日志logo。(自定义Banner)

    SpringBoot项目默认启动时,日志中会输出如下SpringBoot的日志logo及其版本信息:

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

    在具体项目中,若想订制化属于自己的启动logo,当然也是可以的哟大笑

    其实非常简单,只需在SpringBoot项目的src/main/resources/目录下新建一个banner.txt,然后将ASCII字符画复制进去,启动项目就能替换默认的logo了。例如如下banner.txt内容:

${AnsiColor.BRIGHT_GREEN}
 
                        _..._                                                   .-'''-.                             
                     .-'_..._''.                                               '   _    \             _______       
                   .' .'      '.\/|              __.....__                   /   /` '.   \    _..._   \  ___ `'.    
                  / .'           ||          .-''         '. .-.          .-.   |     \  '  .'     '.  ' |--.\  \   
                 . '             ||         /     .-''"'-.  `.\ \        / /|   '      |  '.   .-.   . | |    \  '  
   ____     _____| |             ||  __    /     /________\   \\ \      / / \    \     / / |  '   '  | | |     |  ' 
  `.   \  .'    /| |             ||/'__ '. |                  | \ \    / /   `.   ` ..' /  |  |   |  | | |     |  | 
    `.  `'    .' . '             |:/`  '. '\    .-------------'  \ \  / /       '-...-'`   |  |   |  | | |     ' .' 
      '.    .'    \ '.          .||     | | \    '-.____...---.   \ `  /                   |  |   |  | | |___.' /'  
      .'     `.    '. `._____.-'/||\    / '  `.             .'     \  /                    |  |   |  |/_______.'/   
    .'  .'`.   `.    `-.______ / |/\'..' /     `''-...... -'       / /                     |  |   |  |\_______|/    
  .'   /    `.   `.           `  '  `'-'`                      |`-' /                      |  |   |  |              
 '----'       '----'                                            '..'                       '--'   '--'              
 
${AnsiColor.BRIGHT_RED}
Application Version: ${application.version}${application.formatted-version}
Spring Boot Version: ${spring-boot.version}${spring-boot.formatted-version}

启动后的效果如下:


关于banner.txt中可以使用如下占位符:

变量描述
${application.version}MANIFEST.MF中声明的应用版本号,例如Implementation-Version: 1.0会打印1.0
${application.formatted-version}MANIFEST.MF中声明的被格式化后的应用版本号(被括号包裹且以v作为前缀),用于显示,例如(v1.0)
${spring-boot.version}当前Spring Boot的版本号,例如1.4.1.RELEASE
${spring-boot.formatted-version}当前Spring Boot被格式化后的版本号(被括号包裹且以v作为前缀), 用于显示,例如(v1.4.1.RELEASE)
${Ansi.NAME}(或${AnsiColor.NAME},${AnsiBackground.NAME}, ${AnsiStyle.NAME})NAME代表一种ANSI编码,具体详情查看AnsiPropertySource
${application.title}MANIFEST.MF中声明的应用title,例如Implementation-Title: MyApp会打印MyApp

ASCII字符画生成工具:

如果让我们手动编辑这些字符画,显然是非常麻烦的一件事,可借助如下工具完成:









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xcbeyond

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值