您好,登錄后才能下訂單哦!
dubbo中ServiceBeanExportedEvent的作用是什么,相信很多沒有經(jīng)驗(yàn)的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。
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 ServiceBean<T> extends ServiceConfig<T> implements InitializingBean, DisposableBean, ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>, 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
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事件時執(zhí)行onServiceBeanExportEvent,這里從localReferenceBeanInvocationHandlerCache移除,然后執(zhí)行ReferenceBeanInvocationHandler的init方法
ServiceBeanExportedEvent繼承了ApplicationEvent,其source為ServiceBean;ServiceBean的export方法會publishExportEvent;ReferenceAnnotationBeanPostProcessor實(shí)現(xiàn)了ApplicationListener的onApplicationEvent方法,接收到ServiceBeanExportedEvent事件時執(zhí)行onServiceBeanExportEvent,這里從localReferenceBeanInvocationHandlerCache移除,然后執(zhí)行ReferenceBeanInvocationHandler的init方法
看完上述內(nèi)容,你們掌握dubbo中ServiceBeanExportedEvent的作用是什么的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。