从前文,我们知道到处都是 BeanDefinition 和 BeanDefinitionHolder, 那么他们到底是什么呢?
1.BeanDefinition 定义
2.BeanDefinitionHolder 定义:
主要是持有了 BeanDefinition 对象 && 重命名,核心还在 BeanDefinition
3.BeanDefinition 实现
beanDefinition 加载样例:
4.查看几个 BeanDefinition 的定义:
(1)RootBeanDefinition
(2) ConfigurationClassBeanDefinition
class ConfigurationClassBeanDefinitionReader {
private void loadBeanDefinitionsForBeanMethod(BeanMethod beanMethod) {
//.....
ConfigurationClassBeanDefinition beanDef = new ConfigurationClassBeanDefinition(configClass, metadata);
beanDef.setResource(configClass.getResource());
beanDef.setSource(this.sourceExtractor.extractSource(metadata, configClass.getResource()));
//.....
}
}
复制代码
(3) ScannedGenericBeanDefinition
public class ClassPathScanningCandidateComponentProvider implements EnvironmentCapable, ResourceLoaderAware {
public Set<BeanDefinition> findCandidateComponents(String basePackage) {
//.......
if (isCandidateComponent(metadataReader)) {
ScannedGenericBeanDefinition sbd = new ScannedGenericBeanDefinition(metadataReader);
}
//.......
}
}
复制代码
(4) AnnotatedGenericBeanDefinition
public class AnnotatedBeanDefinitionReader {
public void registerBean(Class<?> annotatedClass, String name, Class<? extends Annotation>... qualifiers) {
AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
//....
}
}
复制代码
评论