SpringApplication实例的初始化创建

​ 查看SpringApplication实例对象初始化创建的源码信息,核心代码具体如下

java

public SpringApplication(ResourceLoader resourceLoader, Class... primarySources) {

this.sources = new LinkedHashSet();

this.bannerMode = Mode.CONSOLE;

this.logStartupInfo = true;

this.addCommandLineProperties = true;

this.addConversionService = true;

this.headless = true;

this.registerShutdownHook = true;

this.additionalProfiles = new HashSet();

this.isCustomEnvironment = false;

this.resourceLoader = resourceLoader;

Assert.notNull(primarySources, "PrimarySources must not be null");

//把项目启动类.class设置为属性存储起来

this.primarySources = new LinkedHashSet(Arrays.asList(primarySources));

//判断当前webApplicationType应用的类型

this.webApplicationType = WebApplicationType.deduceFromClasspath();

// 设置初始化器(Initializer),最后会调用这些初始化器

this.setInitializers(this.getSpringFactoriesInstances(

ApplicationContextInitializer.class));

// 设置监听器(Listener)

this.setListeners(this.getSpringFactoriesInstances(ApplicationListener.class));

// 用于推断并设置项目main()方法启动的主程序启动类

this.mainApplicationClass = this.deduceMainApplicationClass();

这些内容,是从拉勾教育的《Java工程师高薪训练营》里学到的,课程内容非常全面,还有拉勾的内推大厂服务,推荐你也看看。


佳心
1 声望0 粉丝