Spring 中context.start作用
我们经常会看到 如下代码
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configPath.split("[,\\s]+"));
context.start();
其实该context.start()的作用就是初始话配置文件中的bean对象
//---------------------------------------------------------------------
// Implementation of Lifecycle interface
//--------------------------------------------------------------------- public void start() {
Map lifecycleBeans = getLifecycleBeans();
for (Iterator it = new LinkedHashSet(lifecycleBeans.keySet()).iterator(); it.hasNext();) {
String beanName = (String) it.next();
doStart(lifecycleBeans, beanName);
}
publishEvent(new ContextStartedEvent(this));
} /**
* Start the specified bean as part of the given set of Lifecycle beans,
* making sure that any beans that it depends on are started first.
* @param lifecycleBeans Map with bean name as key and Lifecycle instance as value
* @param beanName the name of the bean to start
*/
private void doStart(Map lifecycleBeans, String beanName) {
Lifecycle bean = (Lifecycle) lifecycleBeans.get(beanName);
if (bean != null) {
String[] dependenciesForBean = getBeanFactory().getDependenciesForBean(beanName); //找到依赖的类
for (int i = 0; i < dependenciesForBean.length; i++) {
doStart(lifecycleBeans, dependenciesForBean[i]);//递归调用找到依赖的类
}
if (!bean.isRunning()) {
bean.start();
}
lifecycleBeans.remove(beanName);
}
}
Spring 中context.start作用的更多相关文章
- Spring中<context:annotation-config/>的作用
spring中<context:annotation-config/>配置的作用,现记录如下: <context:annotation-config/>的作用是向Spring容 ...
- Spring中<context:annotation-config/>
最近在研究Spring中<context:annotation-config/>配置的作用,现记录如下: <context:annotation-config/>的作用是向Sp ...
- spring中context:property-placeholder/元素 转载
spring中context:property-placeholder/元素 转载 1.有些参数在某些阶段中是常量 比如 :a.在开发阶段我们连接数据库时的连接url,username,passwo ...
- spring中 context:property-placeholder 导入多个独立的 .properties配置文件
spring中 context:property-placeholder 导入多个独立的 .properties配置文件? Spring容器采用反射扫描的发现机制,在探测到Spring容器中有一个 o ...
- Spring 中bean的作用、定义
Spring 中bean的作用.定义: 创建一个bean定义,其实质是用该bean定义对应的类来创建真正实例的"配方(recipe)".把bean定义看成一个配方很有意义,它与cl ...
- Spring中FactoryBean的作用和实现原理
BeanFactory与FactoryBean,相信很多刚翻看Spring源码的同学跟我一样很好奇这俩货怎么长得这么像,分别都是干啥用的.BeanFactory是Spring中Bean工厂的顶层接口, ...
- spring中的Log4jConfigListener作用和webapp.root的设置
转:http://blog.sina.com.cn/s/blog_7bbf356c01016wld.html 使用spring中的Log4jConfigListener有如如下好处: 1. 动 ...
- Spring中 <context:property-placeholder 的使用与解析 .properties 配置文件的加载
转: Spring中property-placeholder的使用与解析 Spring中property-placeholder的使用与解析 我们在基于spring开发应用的时候,一般都会将数据库的配 ...
- Spring中ApplicationContextAware的作用
ApplicationContextAware 通过它Spring容器会自动把上下文环境对象调用ApplicationContextAware接口中的setApplicationContext方法. ...
随机推荐
- python 时间处理(time和datetime介绍)
python的有关时间的有哪几种呢?今天我们介绍两个:time和datetime time模块提供各种操作时间的函数 datetime模块定义了下面这几个类: datetime.date:表示日期的类 ...
- Java API —— IO流小结
练习题: 1.复制文本文件 package cn.itcast_01; import java.io.BufferedReader; import java.io.BufferedWriter; im ...
- HDU 4358 Boring counting 树状数组+思路
研究了整整一天orz……直接上官方题解神思路 #include <cstdio> #include <cstring> #include <cstdlib> #in ...
- IOS自带json解析类解析json
- (IBAction)test:(id)sender { NSString *result = @"{\"code\":\"S00000\",\&q ...
- WCf的理解
从 .NET 3.5 开始 WCF 已经支持用 WebHttpBinding 构建 RESTful Web 服务,基于 WCF 框架的 RESTful Web 服务还是建立在 WCF Message ...
- apk反编译(1)用apktool破解apk
1,下载 http://ibotpeaches.github.io/Apktool/ 2,破解 把下载的apktool_2.0.3.jar 和 weixin638android680.apk 拷贝到 ...
- 方法Equals和操作符==的区别
http://www.codeproject.com/Articles/584128/What-is-the-difference-between-equalsequals-and-Eq When w ...
- 自定义sublime代码片段
sublime text 已经有一些他们内置的一些代码片段,但是有时候,这些并不能满足我们,这就需要我们自定义一些代码片段. 步骤如下: 1.打开sublime text 2.选择 tools -&g ...
- js 返回的数据类型 5类
对变量或值调用 typeof 运算符将返回下列值之一: undefined - 如果变量是 Undefined 类型的 boolean - 如果变量是 Boolean 类型的 number - 如果变 ...
- char型变量中能存贮一个中文汉字
char型变量是用来存储Unicode编码的字符的,unicode编码字符集中包含了汉字,所以,char型变量中当然可以存储汉字啦.不过,如果某个特殊的汉字没有被包含在unicode编码字符集中,那么 ...