Spring原始碼之註解掃描Component-scan
This method does not
The default implementation checks whether the class is not an interface * and not dependent on an enclosing class. *
Can be overridden in subclasses. * @param beanDefinition the bean definition to check * @return whether the bean definition qualifies as a candidate component */ protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { AnnotationMetadata metadata = beanDefinition.getMetadata(); // metadata.isIndependent() 是獨立的 & // metadata.isConcrete() 是否是介面或者是抽象類 或 // 必須是抽象類 和 有@lookup 註解 return (metadata.isIndependent() && (metadata.isConcrete() || (metadata.isAbstract() && metadata.hasAnnotatedMethods(Lookup.class.getName())))); } ``` 到這裡就已經講完了Component-scan掃描注入的原始碼,這裡涉及代理和annotation-config沒有做詳細的講解,會在後續的文章中做,碼字不易,轉發請註明出處。 ![1615879776045-153328](https://gitee.com/lantaoGitee/picture-bed/raw/master/uPic/20210316/1615879776045-1533