publicinterfaceApplicationContextFactory{ApplicationContextFactoryDEFAULT=(webApplicationType)->{try{switch(webApplicationType){caseSERVLET:returnnewAnnotationConfigServletWebServerApplicationContext();caseREACTIVE:returnnewAnnotationConfigReactiveWebServerApplicationContext();default:returnnewAnnotationConfigApplicationContext();}}catch(Exception ex){thrownewIllegalStateException("Unable create a default ApplicationContext instance, "+"you may need a custom ApplicationContextFactory", ex);}};}
privatevoidprepareContext(DefaultBootstrapContext bootstrapContext,ConfigurableApplicationContext context,ConfigurableEnvironment environment,SpringApplicationRunListeners listeners,ApplicationArguments applicationArguments,Banner printedBanner){//设置容器的环境
context.setEnvironment(environment);//设置容器需要的一些资源postProcessApplicationContext(context);//执行ApplicationContextInitializer.initialize方法applyInitializers(context);
listeners.contextPrepared(context);
bootstrapContext.close(context);if(this.logStartupInfo){logStartupInfo(context.getParent()==null);logStartupProfileInfo(context);}// Add boot specific singleton beansConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
beanFactory.registerSingleton("springApplicationArguments", applicationArguments);if(printedBanner !=null){
beanFactory.registerSingleton("springBootBanner", printedBanner);}if(beanFactory instanceofDefaultListableBeanFactory){((DefaultListableBeanFactory) beanFactory).setAllowBeanDefinitionOverriding(this.allowBeanDefinitionOverriding);}if(this.lazyInitialization){
context.addBeanFactoryPostProcessor(newLazyInitializationBeanFactoryPostProcessor());}// Load the sourcesSet<Object> sources =getAllSources();Assert.notEmpty(sources,"Sources must not be empty");load(context, sources.toArray(newObject[0]));
listeners.contextLoaded(context);}