dubbo中ServiceBeanExportedEvent的作用是什么,相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
創(chuàng)新互聯(lián)建站專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)、鄖西網(wǎng)絡(luò)推廣、重慶小程序開發(fā)、鄖西網(wǎng)絡(luò)營銷、鄖西企業(yè)策劃、鄖西品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)建站為所有大學(xué)生創(chuàng)業(yè)者提供鄖西建站搭建服務(wù),24小時(shí)服務(wù)熱線:13518219792,官方網(wǎng)址:www.cdcxhl.com
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
dubbo-2.7.3/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ServiceBean.java
public class ServiceBeanextends 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方法會(huì)publishExportEvent
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實(shí)現(xiàn)了ApplicationListener的onApplicationEvent方法,接收到ServiceBeanExportedEvent事件時(shí)執(zhí)行onServiceBeanExportEvent,這里從localReferenceBeanInvocationHandlerCache移除,然后執(zhí)行ReferenceBeanInvocationHandler的init方法
ServiceBeanExportedEvent繼承了ApplicationEvent,其source為ServiceBean;ServiceBean的export方法會(huì)publishExportEvent;ReferenceAnnotationBeanPostProcessor實(shí)現(xiàn)了ApplicationListener的onApplicationEvent方法,接收到ServiceBeanExportedEvent事件時(shí)執(zhí)行onServiceBeanExportEvent,這里從localReferenceBeanInvocationHandlerCache移除,然后執(zhí)行ReferenceBeanInvocationHandler的init方法
看完上述內(nèi)容,你們掌握dubbo中ServiceBeanExportedEvent的作用是什么的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!