Dubbo的最新源码中ServiceBean并没有实现Appli
2020-04-23 本文已影响0人
北星七斗
最近在准备面试,在Github上把Dubbo的master代码导下来,然后白嫖别人的写的服务暴露博客,顺着别人思路看下来,发现ServiceBean在最新的源码中并没有实现
ApplicationListener
这个接口
最新的ServiceBean:

非最新的ServiceBean:

经过对比发现最新的继承的是
ApplicationEventPublisherAware
接口,而旧版本的继承的是ApplicationListener<ContextRefreshedEvent>
接口
大部分博客视频讲解服务暴露的export方法根源是ServiceConfig
的export方法,ServiceBean继承了ServiceConfig,利用实现ApplicationListener<ContextRefreshedEvent>
接口的onApplicationEvent方法最终调用ServiceConfig的export方法

然而最新版本实现的
ApplicationEventPublisherAware
并没有去调用ServiceConfig的export方法,只是ServiceBean在完成export的时候利用这个接口去发布一个exported的事件,也就是暴露后的事件,并不是暴露事件
所以新继承的
ApplicationEventPublisherAware
这个接口好像并没有直接对服务暴露过程有作用。那么ServiceConfig的export的方法到底再哪里才会进行调用呢?
追根溯源发现DubboBootstrapApplicationListener这个类,继承了ApplicationListener和ApplicationContextAware,并最后调用到DubboBootStrap方法

发现它再start方法中有一行exportServices,顾名思义是导出服务或者暴露服务

这个exportServices会最中调用ServiceConfigBase的export方法
