2.register(componentClasses); //注册配置类
-->org.springframework.context.annotation.AnnotatedBeanDefinitionReader#register //可以传递多个配置类,所以此处循环注册bean
-->org.springframework.context.annotation.AnnotatedBeanDefinitionReader#doRegisterBean
-->org.springframework.context.annotation.AnnotatedBeanDefinitionReader#doRegisterBean,该方法源码如下:
<T> void doRegisterBean(Class<T> beanClass, @Nullable Supplier<T> instanceSupplier, @Nullable String name,
@Nullable Class<? extends Annotation>[] qualifiers, BeanDefinitionCustomizer... definitionCustomizers) {
//将配置类转换为未注册的被注解的BeanDefinition
AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(beanClass);
if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {
return;
}
abd.setInstanceSupplier(instanceSupplier);
//获取scope属性。设置给beanDefinition
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(abd);
abd.setScope(scopeMetadata.getScopeName());
String beanName = (name != null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));
//根据源数据设置 lazy Primary DependsOn Role Description
AnnotationConfigUtils.processCommonDefinitionAnnotations(abd);
if (qualifiers != null) {
for (Class<? extends Annotation> qualifier : qualifiers) {
if (Primary.class == qualifier) {
abd.setPrimary(true);
}
else if (Lazy.class == qualifier) {
abd.setLazyInit(true);
}
else {
abd.addQualifier(new AutowireCandidateQualifier(qualifier));
}
}
}
for (BeanDefinitionCustomizer customizer : definitionCustomizers) {
customizer.customize(abd);
}
BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(abd, beanName);
//根据ScopedProxyMode属性的值,判断是否要创建一个代理的BeanDefinitionHolder???这个有点懵
//不过此时值为NO,返回的仍为原来的值,暂时不考虑
definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);
//注册配置类
BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);
}
->org.springframework.beans.factory.support.BeanDefinitionReaderUtils#registerBeanDefinition// 此处的注册过程同(一)中的注册方法