Spring核心部分提供了几种内建模式的注解,如@Component、@Service、@Repository、@Controller、@RestController以及@Configrution,但是Spring Framework并不限于这些内建模式注解,也可以自定义模式注解,Spring模式注解可理解为@Component"派生"注解
- Spring Framework 2.x只支持单层的@Component派生
- Spring Framework 3.0.0.RELEASE 后开始支持@Component,但是仅仅支持两层@Component派生(AnnotationAttributesReadingVisitor仅支持了两个for循环)
- Spring Framework 4.0.0.RELEASE 后开始支持多层次的@Component派生(AnnotationAttributesReadingVisitor采用递归)
ClassPathBeanDefinitionScanner允许自定义类型过滤规则,因此,Dubbo的@Service在没有标注@Component的情况下,通过scanner.addIncludeFilter(newAnnotationTypeFilter(Service.class))的方式达到了识别@Service所标注类的目的,不过这种方式没有用到@Component的派生性
网友评论