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 */@SpringBootApplicationpublic class SpringbootApplication { public static void main(String[] args) { SpringApplication.run(SpringbootApplication.class, args); }}
复制代码
关于 SpringApplication 有以下常用特性:
自定义启动日志 logo。(自定义 Banner)
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: 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 中可以使用如下占位符:
ASCII 字符画生成工具:
如果让我们手动编辑这些字符画,显然是非常麻烦的一件事,可借助如下工具完成:
评论