Skip to content

Stub Proxy 配置 Bug #151

@xiegengcai

Description

@xiegengcai

配置描述

文档描述

当定义BarService并定义BarServiceStub时,配置如下其实是不会生效的

<dubbo:service interface="com.foo.BarService" stub="true" />

源码跟踪

com.alibaba.dubbo.config.ServiceConfig#doExport()

if(local !=null){   // 文档中并没有与local相关的参数解释
    if(local=="true"){
        local=interfaceName+"Local";
    }
    Class<?> localClass;
    try {
        localClass = ClassHelper.forNameWithThreadContextClassLoader(local);
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
    if(!interfaceClass.isAssignableFrom(localClass)){
        throw new IllegalStateException("The local implemention class " + localClass.getName() + " not implement interface " + interfaceName);
    }
}

if(stub !=null){
    if(stub=="true"){ // 最坑爹的错误是这里,文档说stub="true"默认interfaceName+Local(实际是+Stub,参见下一个注释),可是这是String对象啊,如果外面stub赋值不是stub="true"的话,设置了true也不会进来,应该修改为stub.equals("true"),上面Local也一样
        stub=interfaceName+"Stub";  // 这里文档中的解释有误,文档中写的是+Local,即与上面的Local一致
    }
    Class<?> stubClass;
    try {
        stubClass = ClassHelper.forNameWithThreadContextClassLoader(stub);
    } catch (ClassNotFoundException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
    if(!interfaceClass.isAssignableFrom(stubClass)){
        throw new IllegalStateException("The stub implemention class " + stubClass.getName() + " not implement interface " + interfaceName);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions