dubbo 2.7.7服务发布流程

406 阅读1分钟

一、启动入口 EnableDubbo注解

EnableDubbo内含有注解@DubboComponentScan,而@Import(DubboComponentScanRegistrar.class)包含在注解中,那让跟进去看看这个class类做了什么

实现spring的ImportBeanDefinitionRegistrar重写了registerBeanDefinitions方法,主要做了三件事:

  • 1.找出要扫描的路径包集合
  • 2.注册ServiceAnnotationBeanPostProcessor,而这里面又会注册到一个很关键的类DubboBootstrapApplicationListener
  • 3.注册一些要用到的类

二、dubbo的正式启动

DubboBootstrapApplicationListener实现了aplicationListener,在spring contextRefreshed事件结束后执行,走到DubboBootstrap的start方法开始dubbo的初始化服务发布之路

public DubboBootstrap start() {
        //cas方法确保只执行一次
        if (started.compareAndSet(false, true)) {
            //初始化
            initialize();
            if (logger.isInfoEnabled()) {
                logger.info(NAME + " is starting...");
            }
            // 服务发布
            exportServices();

            // Not only provider register
            if (!isOnlyRegisterProvider() || hasExportedServices()) {
                // 2. export MetadataService
                exportMetadataService();
                //3. Register the local ServiceInstance if required
                registerServiceInstance();
            }

            referServices();

            if (logger.isInfoEnabled()) {
                logger.info(NAME + " has started.");
            }
        }
        return this;
    }
    ```