SpringApplication.run做了哪些事

SpringApplication.run做了哪些事?

  * Class that can be used to bootstrap and launch a Spring application from a Java main  method. By default class will perform the following steps to bootstrap your application: 
  * Create an appropriate {[@link](https://my.oschina.net/u/393) ApplicationContext} instance (depending on your classpath)
  * Register a {[@link](https://my.oschina.net/u/393) CommandLinePropertySource} to expose command line arguments as  Spring properties
  * Refresh the application context, loading all singleton beans 
  * Trigger any {[@link](https://my.oschina.net/u/393) CommandLineRunner} beans

译文:

是一个可以从main函数中引导和加载Spring应用程序。默认地,class将执行以下步骤:
1.从类路径中创建一个恰当的ApplicationContext实例(应用上下文实例);
2.注册一个CommandLinePropertySource,用于暴露命令行参数作为Spring的属性;
3.唤醒应用上下文,加载所有的单例beans;
4.触发所有的CommandLineRunner beans

网友答案:

 SpringApplication.run一共做了两件事,一件是创建SpringApplication对象,在该对象初始化时,找到配置的事件监听器,并保存起来.第二件事就是运行run方法,此时会将刚才保存的事件监听器根据当前时机触发不同的事件,比如容器初始化,容器创建完成等.同时也会刷新IoC容器,进行组件的扫描、创建、加载等工作.这两件事我都看过源码,我分别给你画个图细致讲一讲.

转载于:https://my.oschina.net/grittan/blog/3054481

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值