dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

Extension type (interface com.alibaba.dubbo.registry.RegistryFactory) is not an extension, because it is NOT annotated with @SPI!

Open iwhalecloud-platform opened this issue 6 years ago • 5 comments

  • [ ] I have searched the issues of this repository and believe that this is not a duplicate.
  • [ ] I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.7.4.1
  • Operating System version: mac
  • Java version: 8

Steps to reproduce this issue

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

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

}

ExtensionLoader.getExtensionLoader(com.alibaba.dubbo.registry.RegistryFactory.class);抛出异常

iwhalecloud-platform avatar Apr 21 '20 14:04 iwhalecloud-platform

这个问题,是你的包冲突了。

CodeIngL avatar Apr 22 '20 02:04 CodeIngL

这个问题,是你的包冲突了。

应该不是jar冲突。我写了个简单的demo就一个dubbo,也报错。

com.alibaba.dubbo.registry.RegistryFactory.class.isAnnotationPresent(SPI.class)

结果是false,即使在SPI注解里添加@Inherited也不行,接口不能传递下去,普通类可以

iwhalecloud-platform avatar Apr 22 '20 03:04 iwhalecloud-platform

   private static <T> boolean withExtensionAnnotation(Class<T> type) {
        return type.isAnnotationPresent(SPI.class);
    }

改成

 private static <T> boolean withExtensionAnnotation(Class<T> type) {
        boolean isExtension =  type.isAnnotationPresent(SPI.class);
        if(!isExtension) {
            for (Class<?> ifc : type.getInterfaces()) {
                isExtension = withExtensionAnnotation(ifc);
                if (isExtension) {
                    return isExtension;
                }
            }

            Class<?> superclass = type.getSuperclass();
            if (superclass == null || Object.class == superclass) {
                return false;
            }
            return  withExtensionAnnotation(superclass);
        }
        return isExtension;
    }

iwhalecloud-platform avatar Apr 22 '20 05:04 iwhalecloud-platform

解决了这个,还有下一个?我能否则在入口,判断type类型,如果是com.alibaba.dubbo.registry.RegistryFactory就使用org.apache开头的

public static <T> ExtensionLoader<T> getExtensionLoader(Class<T> type) {

iwhalecloud-platform avatar Apr 22 '20 05:04 iwhalecloud-platform

任何你觉得有问题需要改开源分支,你可以使用dubbo-wrapper项目进行深度的定制化 https://github.com/open-wrapper/dubbo-wrapper

CodeIngL avatar Apr 23 '20 07:04 CodeIngL