SpringApplication 類提供了一個方便的方式來引導 Spring 應用程序 main() 方法。在許多情況下,您可以委派靜態SpringApplication.run方法,如以下示例所示:
public static void main(String[] args) {
SpringApplication.run(MySpringConfiguration.class, args);
}
當 Spring 應用程序啟動時,會有以下輸出:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: v2.0.3.RELEASE
2013-07-31 00:08:16.117 INFO 56603 --- [ main] o.s.b.s.app.SampleApplication : Starting SampleApplication v0.1.0 on mycomputer with PID 56603 (/apps/myapp.jar started by pwebb)
2013-07-31 00:08:16.166 INFO 56603 --- [ main] ationConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6e5a8246: startup date [Wed Jul 31 00:08:16 PDT 2013]; root of context hierarchy
2014-03-04 13:09:54.912 INFO 41370 --- [ main] .t.TomcatServletWebServerFactory : Server initialized with port: 8080
2014-03-04 13:09:56.501 INFO 41370 --- [ main] o.s.b.s.app.SampleApplication : Started SampleApplication in 2.992 seconds (JVM running for 3.658)
自定義啟動橫幅
默認橫幅如下所示:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: v2.0.3.RELEASE
修改它,只需要在類路徑下添加 banner.txt 或者 banner.jpg 或者 banner.png 或者 banner.gif,或者配置 spring.banner.location 的值為 banner.txt 文件所在位置,如下圖所示:
image.png
除此之外,橫幅還有一下配置:
//配置 banner 的編碼格式
spring.banner.charset
//將圖像轉換為ASCII藝術表示,并打印在任何文本橫幅上方
spring.banner.image.location
//值為 console 時,表示只在 console 輸出
//值為 log 時, 表示記錄到日志里
//值為 off 時,表示不輸出 banner,也可使用 SpringApplication.setBanner(Banner banner?)
spring.main.banner-mode
自定義打印 banner 方式,只需實現 org.springframework.boot.Banner 接口,實現 printBanner() 方法即可。