Spring中的那些【Metadata】(基础)

1.针对Spring版本为5.0.7

1.Meta-annotations(注解元数据)
首先,先理解一个概念,元注解,从Spring(5.0.16)官方文档中有这样一句话

Meta-annotations
Many of the annotations provided by Spring can be used as meta-annotations in 
your own code. A meta-annotation is simply an annotation that can be applied to another annotation.
 For example, the @Service annotation mentioned above is meta-annotated with @Component:

注解上的注解 Spring 将其定义为元注解(meta-annotation),如 @Component标注在 
@Service上,@Component 就被称作为元注解。后面我们就将注解的注解称为元注解。
@Component 是@Service的元注解

ps:元注解是@Component 的注解(@Repository,@Service,@Controller,@Configuration等)
  1. AnnotationMetadata(注解元数据)
    这个接口是用来做什么的呢, 其实可以简单的把这个类当作是一个类的元数据管理,比如这个类是抽象类还是接口,有哪些注解,有那么方法,元注解判断等,方法的方法元数据(MethodMetadata)
    比如判断是否有元注解@Component
metadata.hasAnnotation(Component .class.getName())
ps:这个也是作为包扫描的条件之一
  1. AnnotationMetadata的几个实现
AnnotationMetadataReadingVisitor (基于asm实现,效率高但是代码难度大)
StandardAnnotationMetadata(基于反射,简单但效率低)
这两个在代码中都有用到
image.png
image.png

这两个类没做分析,有兴趣的可以自己分析一下,此文章仅作为笔记进行参考,能力有限,难免有错。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容