暴露服务时序:原图地址:http://dubbo.apache.org/zh-cn/docs/dev/design.html
解析service标签,会将service标签封装成ServiceBean:
ServiceBean怎么做:
public class ServiceBean<T> extends ServiceConfig<T>
implements InitializingBean, DisposableBean, ApplicationContextAware,
ApplicationListener<ContextRefreshedEvent>, BeanNameAware {...}
1.ServiceBean实现了InitializingBean:
- InitializingBean是Spring里面的一个重要接口,当组件创建完对象之后,会调用InitializingBean;
- 在属性设置完之后,会调用afterPropertiesSet方法:
2.ServiceBean实现了ApplicationListener:
- 应用的监听器,Spring原理里面核心的一部分;
- ApplicationListener监听的事件是:ContextRefreshedEvent;
- 当IOC容器刷新完成/IOC容器里面所有对象创建完,会回调ApplicationListener里面的onApplicationEvent方法;
3.ServiceBean在容器创建完对象以后,调用方法afterPropertiesSet;
还会在IOC容器启动完成后,调用onApplicationEvent;
public class ServiceBean<T> extends ServiceConfig<T>
implements InitializingBean, DisposableBean, ApplicationContextAware,
ApplicationListener<ContextRefreshedEvent>, BeanNameAware {
...
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
...
}
...
@Override
@SuppressWarnings({"unchecked", "deprecation"})
public void afterPropertiesSet() throws Exception {
...
}
...
}
ServiceBean的afterPropertiesSet方法里面有如下内容:
public void afterPropertiesSet() throws Exception {
...
setProvider(providerConfig);
...
setApplication(applicationConfig);
...
setModule(moduleConfig);
...
super.setRegistries(registryConfigs);
...
setMonitor(monitorConfig);
...
super.setProtocols(protocolConfigs);
...
}
setProvider(providerConfig):是将标签里面配的provider信息保存起来,保存到当前的ServiceBean里面;setApplication(applicationConfig);setModule(moduleConfig);super.setRegistries(registryConfigs);