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 2021/12/07 05:22:56 UTC

[GitHub] [dubbo] dubuwang123 opened a new issue #9364: dubbo3.0使用了不同的ClassPool,导致动态类无法暴露服务

dubuwang123 opened a new issue #9364:
URL: https://github.com/apache/dubbo/issues/9364


   
   ### Environment
   
   * Dubbo version: 3.0.4
   * Operating System version: windows10
   * Java version: 1.8
   
   ### Steps to reproduce this issue
   
   1. 使用dubbo的默认classpool工具ClassGenerator动态创建接口类
   2. 启动报错
   org.apache.dubbo.common.bytecode.Wrapper类中
   129行  使用了  ClassLoader cl = ClassUtils.getClassLoader(c);
   但是157行使用了          final ClassPool classPool = new ClassPool(ClassPool.getDefault());
   导致在157行提示找不到类的错误
   
   


-- 
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


[GitHub] [dubbo] fl061157 removed a comment on issue #9364: dubbo3.0使用了不同的ClassPool,导致动态类无法暴露服务

Posted by GitBox <gi...@apache.org>.
fl061157 removed a comment on issue #9364:
URL: https://github.com/apache/dubbo/issues/9364#issuecomment-987654859


   你用这个 ClassGenerator.getClassPool(classLoader); 代替你的 ClassPool classPool = new ClassPool(ClassPool.getDefault()); 呢


-- 
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


[GitHub] [dubbo] AlbumenJ closed issue #9364: dubbo3.0使用了不同的ClassPool,导致动态类无法暴露服务

Posted by GitBox <gi...@apache.org>.
AlbumenJ closed issue #9364:
URL: https://github.com/apache/dubbo/issues/9364


   


-- 
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


[GitHub] [dubbo] fl061157 commented on issue #9364: dubbo3.0使用了不同的ClassPool,导致动态类无法暴露服务

Posted by GitBox <gi...@apache.org>.
fl061157 commented on issue #9364:
URL: https://github.com/apache/dubbo/issues/9364#issuecomment-987721141


   确实是个问题。这个没办法,要你自己 重新实现个 ClassLoader ,重写里面的  findResource 方法


-- 
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


[GitHub] [dubbo] fl061157 commented on issue #9364: dubbo3.0使用了不同的ClassPool,导致动态类无法暴露服务

Posted by GitBox <gi...@apache.org>.
fl061157 commented on issue #9364:
URL: https://github.com/apache/dubbo/issues/9364#issuecomment-987620415


   应该不是这个问题,       代码底下设置了  classPool.insertClassPath(new CustomizedLoaderClassPath(cl));  关键是 当前Wrapper.makeWrapper 代码在哪里跑的。 比如 Consumer  ReferenceBean.get() 触发 getMethods() 方法, 就是在 EventLoop 的 IO 线程里跑的, 要确保 那个 IO 线程的Thread.currentThread().getContextClassLoader()能够 Load到你的动态类。  


-- 
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


[GitHub] [dubbo] AlbumenJ commented on issue #9364: dubbo3.0使用了不同的ClassPool,导致动态类无法暴露服务

Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #9364:
URL: https://github.com/apache/dubbo/issues/9364#issuecomment-998861616


   https://github.com/apache/dubbo/pull/9386 修改后会在使用 javassist 生成代理类失败的时候(如果类是动态加载或者 cglib 增强过的)会自动回落尝试 JDK 动态代理,如果 JDK 动态代理成功则不会报错


-- 
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


[GitHub] [dubbo] dubuwang123 commented on issue #9364: dubbo3.0使用了不同的ClassPool,导致动态类无法暴露服务

Posted by GitBox <gi...@apache.org>.
dubuwang123 commented on issue #9364:
URL: https://github.com/apache/dubbo/issues/9364#issuecomment-987664697


   这是我的业务逻辑:
   我在主线程中使用 ClassPool cp = ClassGenerator.getClassPool(Thread.currentThread().getContextClassLoader());
   来创建动态类,然后调用referenceConfig.setInterface(clazz); referenceConfig.get()
   org.apache.dubbo.common.bytecode.Wrapper类中的162行报找不到类,但是如果想办法跳过这里 直接执行到276行Class<?&gt; wc = cc.toClass();(因为253行使用了classpool ClassGenerator cc = ClassGenerator.newInstance(cl);)却能执行通过
   不知为何 classPool.insertClassPath(new CustomizedLoaderClassPath(cl)); 没有生效
   同样的逻辑代码2.6.11是没有问题的
   这是我的test示例
   public static void main(String[] args) throws Exception {
   		ClassPool cp = ClassGenerator.getClassPool(Thread.currentThread().getContextClassLoader());
   		CtClass cc = cp.makeInterface("com.y.Tts");
   		Class infclazz=cc.toClass();
   		ClassLoader cl = ClassUtils.getClassLoader(infclazz);
   		final ClassPool classPool = new ClassPool(ClassPool.getDefault());
   		classPool.insertClassPath(new CustomizedLoaderClassPath(cl));
   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //这个可以
   		ClassGenerator.getClassPool(cl).get(infclazz.getName());
   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//这种不行&nbsp;javassist.NotFoundException: com.y.Tts
   		classPool.get(infclazz.getName())
   
   
   
   
   ------------------&nbsp;原始邮件&nbsp;------------------
   发件人: ***@***.***&gt;; 
   发送时间: 2021年12月7日(星期二) 下午3:45
   收件人: ***@***.***&gt;; 
   抄送: ***@***.***&gt;; ***@***.***&gt;; 
   主题: Re: [apache/dubbo] dubbo3.0使用了不同的ClassPool,导致动态类无法暴露服务 (Issue #9364)
   
   
   
   
   
    
   你用这个 ClassGenerator.getClassPool(classLoader); 代替你的 ClassPool classPool = new ClassPool(ClassPool.getDefault()); 呢
    
   —
   You are receiving this because you authored the thread.
   Reply to this email directly, view it on GitHub, or unsubscribe.
   Triage notifications on the go with GitHub Mobile for iOS or Android.


-- 
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


[GitHub] [dubbo] dubuwang123 commented on issue #9364: dubbo3.0使用了不同的ClassPool,导致动态类无法暴露服务

Posted by GitBox <gi...@apache.org>.
dubuwang123 commented on issue #9364:
URL: https://github.com/apache/dubbo/issues/9364#issuecomment-987649668


   > 应该不是这个问题, 代码底下设置了 classPool.insertClassPath(new CustomizedLoaderClassPath(cl)); 关键是 当前Wrapper.makeWrapper 代码在哪里跑的。 比如 Consumer ReferenceBean.get() 触发 getMethods() 方法, 就是在 EventLoop 的 IO 线程里跑的, 要确保 那个 IO 线程的Thread.currentThread().getContextClassLoader()能够 Load到你的动态类。
   
   我写了个main方法试了一下,确实不行
   `public static void main(String[] args) throws Exception {
   		ClassPool cp = ClassGenerator.getClassPool(Thread.currentThread().getContextClassLoader());
   		CtClass cc = cp.makeInterface("com.y.Tts");
   		Class infclazz=cc.toClass();
   		ClassLoader cl = ClassUtils.getClassLoader(infclazz);
   		final ClassPool classPool = new ClassPool(ClassPool.getDefault());
   		//System.out.println(classPool.get(infclazz.getName()));
   		classPool.insertClassPath(new CustomizedLoaderClassPath(cl));
   		System.out.println(classPool.get(infclazz.getName()));`
   
   `Exception in thread "main" javassist.NotFoundException: com.y.Tts`
   


-- 
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


[GitHub] [dubbo] dubuwang123 commented on issue #9364: dubbo3.0使用了不同的ClassPool,导致动态类无法暴露服务

Posted by GitBox <gi...@apache.org>.
dubuwang123 commented on issue #9364:
URL: https://github.com/apache/dubbo/issues/9364#issuecomment-987633113


   > 2\. 253行
   我在主线程中使用  ClassPool cp = ClassGenerator.getClassPool(Thread.currentThread().getContextClassLoader());
   来创建动态类,然后调用referenceConfig.setInterface(clazz); referenceConfig.get()
   org.apache.dubbo.common.bytecode.Wrapper类中的162行报找不到类,但是如果想办法跳过这里  直接执行到276行Class<?> wc = cc.toClass();(因为253行使用了classpool ClassGenerator cc = ClassGenerator.newInstance(cl);)却能执行通过
   不知为何 classPool.insertClassPath(new CustomizedLoaderClassPath(cl)); 没有生效
   同样的逻辑代码2.6.11是没有问题的
   


-- 
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


[GitHub] [dubbo] fl061157 commented on issue #9364: dubbo3.0使用了不同的ClassPool,导致动态类无法暴露服务

Posted by GitBox <gi...@apache.org>.
fl061157 commented on issue #9364:
URL: https://github.com/apache/dubbo/issues/9364#issuecomment-987654859


   你用这个 ClassGenerator.getClassPool(classLoader); 代替你的 ClassPool classPool = new ClassPool(ClassPool.getDefault()); 呢


-- 
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


[GitHub] [dubbo] AlbumenJ commented on issue #9364: dubbo3.0使用了不同的ClassPool,导致动态类无法暴露服务

Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #9364:
URL: https://github.com/apache/dubbo/issues/9364#issuecomment-998860673


   https://github.com/apache/dubbo/pull/9386


-- 
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