首页 > 其他 > 详细

@DubboComponentScan注解解读

时间:2021-03-17 22:38:23      阅读:85      评论:0      收藏:0      [点我收藏+]

一    DubboComponentScan查看这个注解包含那些

  技术分享图片

二   进入DubboComponentScanRegistrar 

      因为该类实现了ImportBeanDefinitionRegistrar接口,springboot刷新上下文的时候会调用registerBeanDefinitions方法(具体调用https://www.cnblogs.com/kjcc/p/13895903.html)

  下面看这个方法做了那些东西:

 (1) 

    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
   //当前扫描包的路径
        Set<String> packagesToScan = getPackagesToScan(importingClassMetadata);

        registerServiceAnnotationBeanPostProcessor(packagesToScan, registry);

        // @since 2.7.6 Register the common beans
        registerCommonBeans(registry);
    }
(2)进入registerServiceAnnotationBeanPostProcessor(packagesToScan, registry);
  
    private void registerServiceAnnotationBeanPostProcessor(Set<String> packagesToScan, BeanDefinitionRegistry registry) {

        BeanDefinitionBuilder builder = rootBeanDefinition(ServiceAnnotationBeanPostProcessor.class);
        builder.addConstructorArgValue(packagesToScan);
        builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();
        BeanDefinitionReaderUtils.registerWithGeneratedName(beanDefinition, registry);

    }

  这个方法主要作用就是ServiceAnnotationBeanPostProcessor把这个类交给spring容器,首先获取到bean的定义,然后调用工具类创建实例交给容器

(3) registerCommonBeans(registry);主要作用就是把dubbo一些定义的后置处理器和监听器交给spring容器

  

        registerInfrastructureBean(registry, ReferenceAnnotationBeanPostProcessor.BEAN_NAME,
                ReferenceAnnotationBeanPostProcessor.class);

        // Since 2.7.4 [Feature] https://github.com/apache/dubbo/issues/5093
        registerInfrastructureBean(registry, DubboConfigAliasPostProcessor.BEAN_NAME,
                DubboConfigAliasPostProcessor.class);

        // Since 2.7.5 Register DubboLifecycleComponentApplicationListener as an infrastructure Bean
        registerInfrastructureBean(registry, DubboLifecycleComponentApplicationListener.BEAN_NAME,
                DubboLifecycleComponentApplicationListener.class);

        // Since 2.7.4 Register DubboBootstrapApplicationListener as an infrastructure Bean
        registerInfrastructureBean(registry, DubboBootstrapApplicationListener.BEAN_NAME,
                DubboBootstrapApplicationListener.class);

        // Since 2.7.6 Register DubboConfigDefaultPropertyValueBeanPostProcessor as an infrastructure Bean
        registerInfrastructureBean(registry, DubboConfigDefaultPropertyValueBeanPostProcessor.BEAN_NAME,
                DubboConfigDefaultPropertyValueBeanPostProcessor.class);

 

 

 

 

@DubboComponentScan注解解读

原文:https://www.cnblogs.com/kjcc/p/14550297.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!