前言
AnnotatedGenericBeanDefinition 继承了GenericBeanDefinition
主要功能是真的 类注解初始化的一些定义
继承图
源码
- 可以看到这个方法并没有过多的函数,大部分函数都由父类的父类搞完了 ,该类的主要功能就是 对元数据进行操作
public class AnnotatedGenericBeanDefinition extends GenericBeanDefinition implements AnnotatedBeanDefinition {
// 当前Bean的注解元数据
private final AnnotationMetadata metadata;
// 存储工厂方法的元数据
@Nullable
private MethodMetadata factoryMethodMetadata;
/**
* Create a new AnnotatedGenericBeanDefinition for the given bean class.
* @param beanClass the loaded bean class
*/
public AnnotatedGenericBeanDefinition(Class<?> beanClass) {
setBeanClass(beanClass);
//获取元数据
this.metadata = AnnotationMetadata.introspect(beanClass);
}
/**
* Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
* allowing for ASM-based processing and avoidance of early loading of the bean class.
* Note that this constructor is functionally equivalent to
* {@link org.springframework.context.annotation.ScannedGenericBeanDefinition
* ScannedGenericBeanDefinition}, however the semantics of the latter indicate that a
* bean was discovered specifically via component-scanning as opposed to other means.
* @param metadata the annotation metadata for the bean class in question
* @since 3.1.1
*/
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata) {
Assert.notNull(metadata, "AnnotationMetadata must not be null");
if (metadata instanceof StandardAnnotationMetadata) {
setBeanClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass());
}
else {
setBeanClassName(metadata.getClassName());
}
this.metadata = metadata;
}
/**
* Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
* based on an annotated class and a factory method on that class.
* @param metadata the annotation metadata for the bean class in question
* @param factoryMethodMetadata metadata for the selected factory method
* @since 4.1.1
*/
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata, MethodMetadata factoryMethodMetadata) {
this(metadata);
Assert.notNull(factoryMethodMetadata, "MethodMetadata must not be null");
setFactoryMethodName(factoryMethodMetadata.getMethodName());
this.factoryMethodMetadata = factoryMethodMetadata;
}
@Override
public final AnnotationMetadata getMetadata() {
return this.metadata;
}
@Override
@Nullable
public final MethodMetadata getFactoryMethodMetadata() {
return this.factoryMethodMetadata;
}
}
其他文章
AnnotationMetadata
MethodMetadata–目前还没使用到… 暂时没分析等用到了就会去分析了~~