前面四个小结讲述了springboot项目的基本使用以及构建,跑起了一个基本的hello world;
从本小结开始,将深入掌握springboot的各个细节;
(1)SpringApplication:
此类位于org.springframework.boot包下面,它提供了静态方法run()来启动整个springboot项目;
import org.springframework.boot.SpringApplication;
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
看他run的源码:
public static ConfigurableApplicationContext run(Class<?>[] primarySources, String[] args) {
return new SpringApplication(primarySources).run(args);
}
public static ConfigurableApplicationContext run(Class<?> primarySource, String... args) {
return run(new Class<?>[] { primarySource }, args);
}
两个方法其实效果一样,第一个方法可能是为了兼容一些还没有习惯用可变参数的开发者们;
返回一个ConfigurableApplicationContext对象,这个对象应该是一个配置应用的上下文对象,
这里具体有哪些,如何而来的,就不深入探究,只需要记得,如果需要一些配置,可以从这里能够获取。