You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/11/24 08:27:34 UTC

[GitHub] [dubbo] AlbumenJ commented on issue #5507: dubbo 生成动态代理的时候 classLoader默认获取有问题

AlbumenJ commented on issue #5507:
URL: https://github.com/apache/dubbo/issues/5507#issuecomment-1326109463

   > @hengyunabc 我的interFaceClass是classLoader加载的,通过下面这种方式就会出现各种异常,核心还是底层生成代理的时候没有使用interFaceClass的classLoader,反而从AppClassLoader去再次加载,然后出现异常
   > 
   > ```java
   >   public static <T> T getReferenceService(ClassLoader classLoader,T interfaceClass, Integer timeOut, String zkAddress,String version, boolean check){
   >         ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
   >         try {
   >             Thread.currentThread().setContextClassLoader(classLoader);
   >             ReferenceConfig<T> reference = new ReferenceConfig<>();
   >             reference.setVersion(version);
   >             reference.setApplication(applicationConfig);
   >             reference.setCheck(check);
   > //          reference.setGroup("recommend-platform");
   >             reference.setTimeout(timeOut);
   >             reference.setRegistry(new RegistryConfig("zookeeper://" + zkAddress));
   >             reference.setInterface((Class<?>) interfaceClass);
   >             T service = reference.get();
   >             return service;
   >         }finally {
   >             Thread.currentThread().setContextClassLoader(oldClassLoader);
   >         }
   >     }
   > ```
   
   Supported in 3.0. Please try.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org