本文主要是介绍Springboot技术内幕,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先Spring的技术内幕,看下Springboot的启动过程,监控SpringIOC的调用过程。
public ConfigurableApplicationContext run(String... args) {//记录程序运行时间StopWatch stopWatch = new StopWatch();stopWatch.start();// ConfigurableApplicationContext Spring 的上下文ConfigurableApplicationContext context = null;Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList<>();configureHeadlessProperty();//从META-INF/spring.factories中获取监听器//1、获取并启动监听器SpringApplicationRunListeners listeners = getRunListeners(args);listeners.starting();try {ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);//2、构造容器环境ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments);//处理需要忽略的BeanconfigureIgnoreBeanInfo(environment);//打印bannerBanner printedBanner = printBanner(environment);///3、初始化容器context = createApplicationContext();//实例化SpringBootExceptionReporter.class,用来支持报告关于启动的错误exceptionReporters = getSpringFactoriesInstances(SpringBootExceptionReporter.class,new Class[]{ConfigurableApplicationContext.class}, context);//4、刷新容器前的准备阶段prepareContext(context, environment, listeners, applicationArguments, printedBanner);//5、刷新容器refreshContext(context);//刷新容器后的扩展接口afterRefresh(context, applicationArguments);stopWatch.stop();if (this.logStartupInfo) {new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), stopWatch);}listeners.started(context);callRunners(context, applicationArguments);} catch (Throwable ex) {handleRunFailure(context, ex, exceptionReporters, listeners);throw new IllegalStateException(ex);}try {listeners.running(context);} catch (Throwable ex) {handleRunFailure(context, ex, exceptionReporters, null);throw new IllegalStateException(ex);}return context;
}
DefaultListableBeanFactory类是具体的实现类呢?
这篇关于Springboot技术内幕的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!