23. SpringApplication

SpringApplication类通过从main()方法启动,提供了一种简便的方法来引导一个Spring应用.在大多数情况下,您可以委托给静态的SpringApplication.run方法,如下例所示:

  1. public static void main(String[] args) {
  2. SpringApplication.run(MySpringConfiguration.class, args);
  3. }

当您的应用程序启动时,您应该能看到类似以下输出的内容:

  1. . ____ _ __ _ _
  2. /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
  3. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  4. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  5. ' |____| .__|_| |_|_| |_\__, | / / / /
  6. =========|_|==============|___/=/_/_/_/
  7. :: Spring Boot :: v2.0.2.RELEASE
  8. 2013-07-31 00:08:16.117 INFO 56603 --- [ main] o.s.b.s.app.SampleApplication :
  9. Starting SampleApplication v0.1.0 on mycomputer with PID 56603 (/apps/myapp.jar started by pwebb)
  10. 2013-07-31 00:08:16.166 INFO 56603 --- [ main]
  11. ationConfigServletWebServerApplicationContext : Refreshing
  12. org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6e5a8246:
  13. startup date [Wed Jul 31 00:08:16 PDT 2013]; root of context hierarchy
  14. 2014-03-04 13:09:54.912 INFO 41370 --- [ main] .t.TomcatServletWebServerFactory : Server
  15. initialized with port: 8080
  16. 2014-03-04 13:09:56.501 INFO 41370 --- [ main] o.s.b.s.app.SampleApplication :
  17. Started SampleApplication in 2.992 seconds (JVM running for 3.658)

默认情况下,INFO级别的日志会信息会显示,包括一些相关的启动细节:比如启动应用程序的用户.如果你需要INFO日志级别以外的其他信息,你可以设置它,如Section 26.4 Log Levels所述.