// 调用 ReferenceConfig 的 get 方法获取 bean 实例
return get();
}
比较上面两个方法,我们可以知道 Spring 在实例化 Dubbo 的 ReferenceBean 时会调用 ReferenceConfig 的 #get 方法获取 bean 实例,执行 Dubbo 服务引用的过程。
[](
)三、配置检查处理
============================================================================
继续跟随 ReferenceConfig 的 #get 方法:
public synchronized T get() {
if (destroyed) {
throw new IllegalStateException(“The invoker of ReferenceConfig(” + url + “) has already destroyed!”);
} // 若服务引用代理为空,执行 init 方法
if (ref == null) {
// 处理配置,调用 createProxy 生成代理类
init();
}
return ref;
}
- ReferenceConfig 的 init( ) 方法
public synchronized void init() {
// 标识是否已经初始化,避免重复初始化
if (initialized) {
return;
} // 获取 DubboBootstrap 引导类实例 if (bootstrap == null) {
bootstrap = DubboBootstrap.getInstance(); bootstrap.init(); } // 检查接口、consumer 等配置是否合法,并对相应的配置赋值 checkAndUpdateSubConfigs(); // 本地存根检查
checkStubAndLocal(interfaceClass); ConfigValidationUtils.checkMock(interfaceClass, this); Map<String, String> map = new HashMap<String, String>();
map.put(SIDE_KEY, CONSUMER_SIDE); // 加入运行时参数,Dubbo 版本号、时间戳、进程号等
ReferenceConfigBase.appendRuntimeParameters(map);
// 是否为泛化接口
if (!ProtocolUtils.isGeneric(generic)) {
String revision = Version.getVersion(interfaceClass, version); if (revision != null && revision.length() > 0) {
map.put(REVISION_KEY, revision); } // 获取接口的方法列表,加入 map
String[] methods = Wrapper.getWrapper(interfaceClass).getMethodNames(); if (methods.length == 0) {
logger.warn("No method found in service interface " + interfaceClass.getName());
map.put(METHODS_KEY, ANY_VALUE); } else {