1. 
服务接口和服务扩展之间是一对多关系,当没有明确指明默认实现时并不是根据接口类型随机指定,而是根据默认扩展来查找,Protocol$Adaptive代码如下所示
```
String extName = (url.getProtocol() == null ? "dubbo" : url.getProtocol());
if (extName == null)
            throw new IllegalStateException("Fail to get 
extension(org.apache.dubbo.rpc.Protocol) name from url(" + url.toString() + ") 
use keys([protocol])");
org.apache.dubbo.rpc.Protocol extension = (org.apache.dubbo.rpc.Protocol) 
ExtensionLoader
                
.getExtensionLoader(org.apache.dubbo.rpc.Protocol.class).getExtension(extName);
```
2. @SPI注解在dubbo框架中是必要参数,ExtensionLoader.java 代码如下所示:

```
public static <T> ExtensionLoader<T> getExtensionLoader(Class<T> type) {
        if (!withExtensionAnnotation(type)) {
            throw new IllegalArgumentException("Extension type(" + type +
                    ") is not extension, because WITHOUT @" + 
SPI.class.getSimpleName() + " Annotation!");
        }
}
```

3. @SPI 中value 值是非必填参数

```
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface SPI {

    /**
     * default extension name
     */
    String value() default "";

}
```

结论:是否应修改@SPI的value值为必须参数,避免在代码中重复判断是否采用默认值。

@diecui1202 





[ Full content available at: 
https://github.com/apache/incubator-dubbo/issues/2398 ]
This message was relayed via gitbox.apache.org for [email protected]

Reply via email to