public ConfigurableApplicationContext run(String... args) {
StopWatch stopWatch = new StopWatch(); //时间计数器,主要记录任务的运行时间 不用管
stopWatch.start();
ConfigurableApplicationContext context = null; //初始化一个可配置应用上下文
FailureAnalyzers analyzers = null; //失败分析器
configureHeadlessProperty(); //设置系统 awt的头属性信息
SpringApplicationRunListeners listeners = getRunListeners(args); //设置多个运行监听器
listeners.starting();
try {
ApplicationArguments applicationArguments = new DefaultApplicationArguments(
args); //设置应用参数
ConfigurableEnvironment environment = prepareEnvironment(listeners,
applicationArguments); //得到创建的环境变量,设置监听器的环境
Banner printedBanner = printBanner(environment); //设置banner,以及banner的资源加载器
context = createApplicationContext(); //创建应用上下文,可配置的web应用上下文或者标准的应用上下文
analyzers = new FailureAnalyzers(context); //设置失败分析器 并且判断是否是beanFactoryAware 如果是 将上下文的beanFactory赋值给它的beanFactory
prepareContext(context, environment, listeners, applicationArguments,
printedBanner); //设置上下文的环境 监听器 应用参数,横幅
refreshContext(context);
afterRefresh(context, applicationArguments);
listeners.finished(context, null);
stopWatch.stop();
if (this.logStartupInfo) {
new StartupInfoLogger(this.mainApplicationClass)
.logStarted(getApplicationLog(), stopWatch);
}
return context;
}
catch (Throwable ex) {
handleRunFailure(context, listeners, analyzers, ex);
throw new IllegalStateException(ex);
}
}
private void prepareContext(ConfigurableApplicationContext context,
ConfigurableEnvironment environment, SpringApplicationRunListeners listeners,
ApplicationArguments applicationArguments, Banner printedBanner) {
context.setEnvironment(environment);
postProcessApplicationContext(context);
applyInitializers(context);
listeners.contextPrepared(context);
if (this.logStartupInfo) {
logStartupInfo(context.getParent() == null);
logStartupProfileInfo(context);
} // Add boot specific singleton beans
context.getBeanFactory().registerSingleton("springApplicationArguments",
applicationArguments);
if (printedBanner != null) {
context.getBeanFactory().registerSingleton("springBootBanner", printedBanner);
} // Load the sources
Set<Object> sources = getSources();
Assert.notEmpty(sources, "Sources must not be empty");
load(context, sources.toArray(new Object[sources.size()]));
listeners.contextLoaded(context);
}
/**
* Load beans into the application context.
* @param context the context to load beans into
* @param sources the sources to load
*/
protected void load(ApplicationContext context, Object[] sources) {
if (logger.isDebugEnabled()) {
logger.debug(
"Loading source " + StringUtils.arrayToCommaDelimitedString(sources));
}
BeanDefinitionLoader loader = createBeanDefinitionLoader(
getBeanDefinitionRegistry(context), sources);
if (this.beanNameGenerator != null) {
loader.setBeanNameGenerator(this.beanNameGenerator);
}
if (this.resourceLoader != null) {
loader.setResourceLoader(this.resourceLoader);
}
if (this.environment != null) {
loader.setEnvironment(this.environment);
}
loader.load();
}
 
protected void postProcessApplicationContext(ConfigurableApplicationContext context) {
if (this.beanNameGenerator != null) {
context.getBeanFactory().registerSingleton(
AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR,
this.beanNameGenerator);
}
if (this.resourceLoader != null) {
if (context instanceof GenericApplicationContext) {
((GenericApplicationContext) context)
.setResourceLoader(this.resourceLoader);
}
if (context instanceof DefaultResourceLoader) {
((DefaultResourceLoader) context)
.setClassLoader(this.resourceLoader.getClassLoader());
}
}
}



private void refreshContext(ConfigurableApplicationContext context) {
refresh(context);
if (this.registerShutdownHook) {
try {
context.registerShutdownHook();
}
catch (AccessControlException ex) {
// Not allowed in some environments.
}
}
}


 

最新文章

  1. 父div高度不能根据子div高度自动变化的解决方案
  2. rsa密钥文件转化为tortoise认可的pak密钥文件
  3. IIS相关知识
  4. Processing与Java混编初探
  5. FZU 1752 A^B mod C(快速加、快速幂)
  6. Andriod环境搭建
  7. Leetcode#140 Word Break II
  8. struts2 集成 easyui
  9. hadoop namenode又一次格式化以后hbase的hmaster进程启动后立即消失
  10. SQLite入门与分析(四)---Page Cache之事务处理(2)
  11. 微软阵营企稳的利好消息:.NET开源、Visual Studio免费
  12. PHP_SELF、 SCRIPT_NAME、 REQUEST_URI 区别
  13. MEF初体验之六:导出和元素据
  14. openGL线s的绘制
  15. 关于ABP聚合根类AggregateRoot的思考
  16. js精要之对象属性
  17. linux卸载openjdk
  18. 不一样的go语言-error
  19. WPFToolkit DataGrid 使用介绍zz
  20. centos7中安装python3.7遇到的问题

热门文章

  1. docker 安装centos7并SSH远程连接
  2. libevent(六)事件监听
  3. 线段树 I - Transformation 加乘优先级
  4. Bootstrap初识
  5. STL下&lt;algorithm&gt;下的reverse函数
  6. 【Hadoop离线基础总结】MapReduce 社交粉丝数据分析 求出哪些人两两之间有共同好友,及他俩的共同好友都有谁?
  7. JUC之ReentrantLock源码分析
  8. vscode调试webpack的启动和打包部署过程,nodejs调试
  9. docker push的时候提示requested access to the resource is denied
  10. Windows基础学习