dubbo有2种方式进行服务暴露:延迟暴露和非延迟暴露
延迟暴露:ServiceBean实现InitializingBean,在bean的属性初始化后都会执行该方法。dubbo通过调用afterPropertySet()方法进行服务暴露
1
2
3
4
5public void afterPropertiesSet() throws Exception {
...
export();
...
}非延迟暴露:ServiceBean实现ApplicationListener,在spring实例化bean后会回调onApplicationEvent,dubbo以此调用export()进行发布
1
2
3
4
5
6
7
8
9
10public void onApplicationEvent(ApplicationEvent event) {
if (ContextRefreshedEvent.class.getName().equals(event.getClass().getName())) {
if (isDelay() && ! isExported() && ! isUnexported()) {
if (logger.isInfoEnabled()) {
logger.info("The service ready on spring started. service: " + getInterface());
}
export();
}
}
}
dubbo进行服务暴露时,有个参数几乎贯穿调用链,那就是URL属性,所有的bean配置都会转化成URL的参数
核心入口就是ServiceConfig类方法
1 | // 根据不同协议进行遍历暴露 |