SpringApplication 類提供了一個(gè)方便的方式來引導(dǎo) Spring 應(yīng)用程序 main() 方法。在許多情況下楣号,您可以委派靜態(tài)SpringApplication.run方法叼耙,如以下示例所示:
public static void main(String[] args) {
SpringApplication.run(MySpringConfiguration.class, args);
}
當(dāng) Spring 應(yīng)用程序啟動(dòng)時(shí)腕窥,會(huì)有以下輸出:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: 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)
自定義啟動(dòng)橫幅
默認(rèn)橫幅如下所示:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: 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
//將圖像轉(zhuǎn)換為ASCII藝術(shù)表示爽撒,并打印在任何文本橫幅上方
spring.banner.image.location
//值為 console 時(shí)入蛆,表示只在 console 輸出
//值為 log 時(shí), 表示記錄到日志里
//值為 off 時(shí)硕勿,表示不輸出 banner,也可使用 SpringApplication.setBanner(Banner banner?)
spring.main.banner-mode
自定義打印 banner 方式哨毁,只需實(shí)現(xiàn) org.springframework.boot.Banner 接口,實(shí)現(xiàn) printBanner() 方法即可源武。