spring中bean实例化前获取BeanDefinition信息
getMergedLocalBeanDefinition完成功能
spring中bean实例化前,会先获取BeanDefinition完整信息,即当前bean及其父类的BeanDefinition信息。
源码
RootBeanDefinition mbd = this.mergedBeanDefinitions.get(beanName);
if (mbd != null && !mbd.stale) {
return mbd;
}
return getMergedBeanDefinition(beanName, getBeanDefinition(beanName));
return getMergedBeanDefinition(beanName, bd, null);
synchronized (this.mergedBeanDefinitions) {}
if (containingBd == null) {
mbd = this.mergedBeanDefinitions.get(beanName);
}
if (bd.getParentName() == null) {
if (bd instanceof RootBeanDefinition) {
mbd = ((RootBeanDefinition) bd).cloneBeanDefinition();
} else {
mbd = new RootBeanDefinition(bd);
}
}
if (!StringUtils.hasLength(mbd.getScope())) {
mbd.setScope(SCOPE_SINGLETON);
}
if (containingBd == null && isCacheBeanMetadata()) {
this.mergedBeanDefinitions.put(beanName, mbd);
}
if (previous != null) {
copyRelevantMergedBeanDefinitionCaches(previous, mbd);
}
return mbd;
细节补充
第一次调用位置
spring的十三太保之五invokeBeanFactoryPostProcessors中执行BeanFactoryPostProcessor时完成调用
|