网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

dubbo中ServiceBeanExportedEvent的作用是什么

dubbo中ServiceBeanExportedEvent的作用是什么,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

创新互联建站专注为客户提供全方位的互联网综合服务,包含不限于网站建设、成都网站建设、郧西网络推广、重庆小程序开发、郧西网络营销、郧西企业策划、郧西品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联建站为所有大学生创业者提供郧西建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com

ServiceBeanExportedEvent

dubbo-2.7.3/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/event/ServiceBeanExportedEvent.java

public class ServiceBeanExportedEvent extends ApplicationEvent {

    /**
     * Create a new ApplicationEvent.
     *
     * @param serviceBean {@link ServiceBean} bean
     */
    public ServiceBeanExportedEvent(ServiceBean serviceBean) {
        super(serviceBean);
    }

    /**
     * Get {@link ServiceBean} instance
     *
     * @return non-null
     */
    public ServiceBean getServiceBean() {
        return (ServiceBean) super.getSource();
    }
}
  • ServiceBeanExportedEvent继承了ApplicationEvent,其source为ServiceBean

ServiceBean

dubbo-2.7.3/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java

public class ServiceBean extends ServiceConfig implements InitializingBean, DisposableBean,
        ApplicationContextAware, ApplicationListener, BeanNameAware,
        ApplicationEventPublisherAware {

        //......

    /**
     * @since 2.6.5
     */
    @Override
    public void export() {
        super.export();
        // Publish ServiceBeanExportedEvent
        publishExportEvent();
    }

    /**
     * @since 2.6.5
     */
    private void publishExportEvent() {
        ServiceBeanExportedEvent exportEvent = new ServiceBeanExportedEvent(this);
        applicationEventPublisher.publishEvent(exportEvent);
    }

        //......
}
  • ServiceBean的export方法会publishExportEvent

ReferenceAnnotationBeanPostProcessor

dubbo-2.7.3/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java

public class ReferenceAnnotationBeanPostProcessor extends AnnotationInjectedBeanPostProcessor implements
        ApplicationContextAware, ApplicationListener {

        //......

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof ServiceBeanExportedEvent) {
            onServiceBeanExportEvent((ServiceBeanExportedEvent) event);
        } else if (event instanceof ContextRefreshedEvent) {
            onContextRefreshedEvent((ContextRefreshedEvent) event);
        }
    }

    private void onServiceBeanExportEvent(ServiceBeanExportedEvent event) {
        ServiceBean serviceBean = event.getServiceBean();
        initReferenceBeanInvocationHandler(serviceBean);
    }

    private void initReferenceBeanInvocationHandler(ServiceBean serviceBean) {
        String serviceBeanName = serviceBean.getBeanName();
        // Remove ServiceBean when it's exported
        ReferenceBeanInvocationHandler handler = localReferenceBeanInvocationHandlerCache.remove(serviceBeanName);
        // Initialize
        if (handler != null) {
            handler.init();
        }
    }

        //......
}
  • ReferenceAnnotationBeanPostProcessor实现了ApplicationListener的onApplicationEvent方法,接收到ServiceBeanExportedEvent事件时执行onServiceBeanExportEvent,这里从localReferenceBeanInvocationHandlerCache移除,然后执行ReferenceBeanInvocationHandler的init方法

小结

ServiceBeanExportedEvent继承了ApplicationEvent,其source为ServiceBean;ServiceBean的export方法会publishExportEvent;ReferenceAnnotationBeanPostProcessor实现了ApplicationListener的onApplicationEvent方法,接收到ServiceBeanExportedEvent事件时执行onServiceBeanExportEvent,这里从localReferenceBeanInvocationHandlerCache移除,然后执行ReferenceBeanInvocationHandler的init方法

看完上述内容,你们掌握dubbo中ServiceBeanExportedEvent的作用是什么的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


本文题目:dubbo中ServiceBeanExportedEvent的作用是什么
标题URL:http://bjjierui.cn/article/jjsedd.html

其他资讯