在 SpringApplication 中提供了 main()方法 用于 spring 容器运行
在很多情况(situations)下 ,你可以 委托(delegate)给经静态的
SpringApplication.run方法
public static void main(String[] args) {
SpringApplication.run(MySpringConfiguration.class, args);
}
当你的运行时,你会看到相似的事情 :
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: v1.4.0.M2 2013-07-31 00:08:16.117 INFO 56603 --- [ 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] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@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.TomcatEmbeddedServletContainerFactory : 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)一
一些默认INFO 日志消息打印出来 ,包括一些容器相关(relevant)的启动信息
23.1 自定义Banner(Customzing the Banner)
Banner打印的信息,你可能通过修改banner.txt 在你的classpath下,
或者设置banner.location 来配置 一个文件,如果文件不是平常的编码,
你可以通过设置banner.charset(默认UTF-8)。在添加 text文件的时候,你也可以添加一个
banner.gif,banner.jpg 或者banner.png 在你的 classpth下 ,或者设置banner.image.location
property,图片会转换(converted) ASCII 样式(art) 展现(representation)出来,并且打印出来
文字的banner. 内置的 banner.txt 文件,你可以使用下面任意的占位符
表格 23.1 Banner 参数
参数 | 说明 |
${application.version} | |
${application.formatted-version} | |
${spring-boot.version} | |
${spring-boot.formatted-version} | |
${Ansi.NAME} (or ${AnsiColor.NAME}, ${AnsiBackground.NAME}, ${AnsiStyle.NAME}) | |
${application.title} |
提示:
SpringApplication.setBanner(...)方法,可以让你生成 你自己程序(programmatically)
定义的Banner, 使用org.springframework.boot.Banner接口 并且实现你自己定义的
printBanner()方法
你也可以使用spring.main.banner-mode 属性 查明(datermine) 当banner是通过
System.out(console)打印出来的,使用配置的日志或者 不是
在打印的banner 是已经注册到了 单例(singleton)的bean中 它的名字是springBootBanner.
Note
YAML maps off 是false 你可以使用这个标签,在你想关闭banner 在的容器中
spring:
main:
banner-mode: "off"
配置结果 :