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/07/18 09:42:06 UTC

[GitHub] [dubbo] xiangzz159 opened a new issue, #10335: 3.0.6 引用dubbo服务时候报错

xiangzz159 opened a new issue, #10335:
URL: https://github.com/apache/dubbo/issues/10335

   <!-- If you need to report a security issue please visit https://github.com/apache/dubbo/security/policy -->
   
   - [ ] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
   
   ### Environment
   
   * Dubbo version: 3.0.6
   * Operating System version: MacOS 10.15.7
   * Java version: 1.8.0_231
   
   ### Steps to reproduce this issue
   
   1. 
   ![image](https://user-images.githubusercontent.com/16982273/179484879-5ba1733a-a137-4f21-bd96-b84da779ab01.png)
   
   2. 
   ![image](https://user-images.githubusercontent.com/16982273/179484986-3568febe-09c6-4d00-8466-a66b0a963e7b.png)
   
   3. 
   ![image](https://user-images.githubusercontent.com/16982273/179485041-7a5f80af-538b-40cd-8609-c604e79cd79a.png)
   
   4. 
   ![image](https://user-images.githubusercontent.com/16982273/179485088-6803ee86-cffe-46d6-af3f-b097a0d085c8.png)
   
   5. 服务启动时报错:
   org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DClient': Injection of @DubboReference dependencies is failed; nested exception is java.lang.IllegalArgumentException: Can not set com.xsyx.router.api.feature.UserAInfo field com.xsyx.router.client.client.DClient.userInfo to com.sun.proxy.$Proxy87
   	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.postProcessPropertyValues(ReferenceAnnotationBeanPostProcessor.java:326)
   	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1418)
   	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601)
   	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)
   	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
   	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
   	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
   	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
   	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944)
   	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
   	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
   	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
   	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
   	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:438)
   	at org.springframework.boot.SpringApplication.run(SpringApplication.java:337)
   	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1336)
   	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1325)
   	at com.xsyx.router.client.ClientApplication.main(ClientApplication.java:16)
   Caused by: java.lang.IllegalArgumentException: Can not set com.xsyx.router.api.feature.UserAInfo field com.xsyx.router.client.client.DClient.userInfo to com.sun.proxy.$Proxy87
   	at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
   	at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
   	at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
   	at java.lang.reflect.Field.set(Field.java:764)
   	at org.apache.dubbo.config.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor$AnnotatedInjectElement.inject(AbstractAnnotationBeanPostProcessor.java:470)
   	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
   	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.postProcessPropertyValues(ReferenceAnnotationBeanPostProcessor.java:322)
   	... 17 common frames omitted
   
   Pls. provide [GitHub address] to reproduce this issue.
   
   ### Expected Behavior
   
   <!-- What do you expect from the above steps?-->
   
   ### Actual Behavior
   
   <!-- What actually happens? -->
   
   If there is an exception, please attach the exception trace:
   
   ```
   Just put your stack trace here!
   ```
   


-- 
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.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] chickenlj commented on issue #10335: 3.0.6 引用dubbo服务时候报错

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

   Fixed in https://github.com/apache/dubbo/pull/10359, please upgrade to the 3.0.11 bugfix version.


-- 
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] liufeiyu1002 commented on issue #10335: 3.0.6 引用dubbo服务时候报错

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

   > BCD三个类在注入依赖bean的时候,因为这三的属性名称一样且类型不一样(会走入你前面截图的逻辑里),按理注入的beanName应该分别为userInfo、userInfo#2、userInfo#3。我理解应该不会出现你所描述的 `beanDefinitionRegistry没有找到已经注册的bean`,我本地试了下没有问题,方便的话可以发一下你的demo我本地复现一下。
   所以在此处
   ![image](https://user-images.githubusercontent.com/32605119/180649503-18781c85-92e8-4dd7-bce0-8e2b28e6ce0e.png)
   对newReferenceBeanName的要求应该是 没有被注册到 beanDefinitionRegistry中 且 别名中也没注册过当前名称,在生成新的newReferenceBeanName名称时 应该二次检查之前是否已经使用当前名称注册过,避免重复的注入多个别名
   


-- 
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] BurningCN commented on issue #10335: 3.0.6 引用dubbo服务时候报错

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

   PR #10359, by [liufeiyu1002](https://github.com/liufeiyu1002)


-- 
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] liufeiyu1002 commented on issue #10335: 3.0.6 引用dubbo服务时候报错

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

   我觉得这种注入的写法是不规范的,当然dubbo 是需要解决这种情况的。[https://github.com/apache/dubbo/pull/10359](url) @xiangzz159 @chenziqiang666 


-- 
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] xiangzz159 commented on issue #10335: 3.0.6 引用dubbo服务时候报错

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

   ![image](https://user-images.githubusercontent.com/16982273/179880422-5d248abc-a139-47dc-b5e3-4e78fa57309e.png)
   这边的代码有问题,beanDefinitionRegistry没有找到已经注册的bean,所以index没有刷新,修改index为一个比较大的值后能正常启动


-- 
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] liufeiyu1002 commented on issue #10335: 3.0.6 引用dubbo服务时候报错

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

   > BCD三个类在注入依赖bean的时候,因为这三的属性名称一样且类型不一样(会走入你前面截图的逻辑里),按理注入的beanName应该分别为userInfo、userInfo#2、userInfo#3。我理解应该不会出现你所描述的 `beanDefinitionRegistry没有找到已经注册的bean`,我本地试了下没有问题,方便的话可以发一下你的demo我本地复现一下。
   
   所以在此处
   ![image](https://user-images.githubusercontent.com/32605119/180649503-18781c85-92e8-4dd7-bce0-8e2b28e6ce0e.png)
   对newReferenceBeanName的要求应该是 没有被注册到 beanDefinitionRegistry中 且 别名中也没注册过当前名称,在生成新的newReferenceBeanName名称时 应该二次检查之前是否已经使用当前名称注册过,避免重复的注入多个别名
   


-- 
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] BurningCN commented on issue #10335: 3.0.6 引用dubbo服务时候报错

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

   @liufeiyu1002 感谢,分析很详细透彻。


-- 
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] BurningCN commented on issue #10335: 3.0.6 引用dubbo服务时候报错

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

   BCD三个类在注入依赖bean的时候,因为这三的属性名称一样且类型不一样(会走入你前面截图的逻辑里),按理注入的beanName应该分别为userInfo、userInfo#2、userInfo#3。我理解应该不会出现你所描述的 `beanDefinitionRegistry没有找到已经注册的bean`,我本地试了下没有问题,方便的话可以发一下你的demo我本地复现一下。


-- 
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] chickenlj closed issue #10335: 3.0.6 引用dubbo服务时候报错

Posted by GitBox <gi...@apache.org>.
chickenlj closed issue #10335: 3.0.6 引用dubbo服务时候报错
URL: https://github.com/apache/dubbo/issues/10335


-- 
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] cycle2zhou commented on issue #10335: 3.0.6 引用dubbo服务时候报错

Posted by "cycle2zhou (via GitHub)" <gi...@apache.org>.
cycle2zhou commented on issue #10335:
URL: https://github.com/apache/dubbo/issues/10335#issuecomment-1430812193

   这个问题好像还存在,把有问题的变量名改一下就好了;
   有问题写法:
   @DubboReference
   private ProjectService projectService;
   没问题写法:
   @DubboReference
   private ProjectService gaeaProjectService;


-- 
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] chenziqiang666 commented on issue #10335: 3.0.6 引用dubbo服务时候报错

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

   我理解原因是spring在生成bean DClient的过程中,当赋值属性UserAInfo userInfo时,是根据名称userInfo查找对应的bean,而不是根据类型UserAInfo查找bean,这个是spring的流程,应该不算dubbo的bug


-- 
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] xiangzz159 commented on issue #10335: 3.0.6 引用dubbo服务时候报错

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

   > BCD三个类在注入依赖bean的时候,因为这三的属性名称一样且类型不一样(会走入你前面截图的逻辑里),按理注入的beanName应该分别为userInfo、userInfo#2、userInfo#3。我理解应该不会出现你所描述的 `beanDefinitionRegistry没有找到已经注册的bean`,我本地试了下没有问题,方便的话可以发一下你的demo我本地复现一下。
   
   https://github.com/xiangzz159/dubbo-client-demo


-- 
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] liufeiyu1002 commented on issue #10335: 3.0.6 引用dubbo服务时候报错

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

   > BCD三个类在注入依赖bean的时候,因为这三的属性名称一样且类型不一样(会走入你前面截图的逻辑里),按理注入的beanName应该分别为userInfo、userInfo#2、userInfo#3。我理解应该不会出现你所描述的 `beanDefinitionRegistry没有找到已经注册的bean`,我本地试了下没有问题,方便的话可以发一下你的demo我本地复现一下。
   
   他截图部分的代码 会在 postProcessBeanFactory 和 postProcessMergedBeanDefinition 俩次触发执行,
   第一次触发:(postProcessBeanFactory )
       A类  beanDefinitionRegistry.registerBeanDefinition("test", UserInfo的beanDefinition);  
       B类 beanDefinitionRegistry.registerBeanDefinition("userInfo", MessageInfo的beanDefinition);
       C类 注册了别名 beanDefinitionRegistry.registerAlias("test", "userInfo#2");
       D 类 beanDefinitionRegistry.registerBeanDefinition("userInfo#2", UserAInfo的beanDefinition);
   第二次触发:(postProcessMergedBeanDefinition )
   ![image](https://user-images.githubusercontent.com/32605119/180646938-51ca6b76-676d-40a0-a0ed-52d6bde2c742.png)
      A类 B类 在上图代码中会从缓存中获取到直接返回
      C类传入的referenceBeanName是userInfo 在 UserInfo类型对应的缓存中是 test/userInfo#2 没有命中缓存,会走到 
   ![image](https://user-images.githubusercontent.com/32605119/180647192-dbf4bd4f-7190-4a7d-82f5-14b48489704e.png)
   这部分执行时 C类获取到 newReferenceBeanName 应该是 userInfo#3 ,因为 userInfo 和 userInfo#2 被 B 和 D 注册到了beanDefinitionRegistry中 ,此时会继续注册alias beanDefinitionRegistry.registerAlias("test", "userInfo#3"); 
     D 类 传入的referenceBeanName是userInfo 在 UserAInfo类型对应的缓存中是 userInfo#2 没有命中缓存,走到上图红框中执行
    D 类获取到 newReferenceBeanName 应该是 userInfo#3 ,因为userInfo被B注册 userInfo#2 被他之前自己注册过了,之后会注册别名 userInfo#3: userInfo#2   此时因为别名  userInfo#3 被  test 注册过了 如果 allowBeanDefinitionOverriding 为false  则会抛出异常
   ![image](https://user-images.githubusercontent.com/32605119/180647334-f8bc4d39-5f2b-48e4-b327-c5e62bfcc9ea.png)
   ![image](https://user-images.githubusercontent.com/32605119/180648380-8c083ff1-b7da-4b6a-8f63-18b7ae9b65a7.png) 
   如果允许覆盖则 别名会变成如图所示
   ![image](https://user-images.githubusercontent.com/32605119/180648248-60a88d98-0d24-436b-8c05-346bf0f907be.png)  之后当前D类的 AnnotatedFieldElement的 injectedObject 值被设置为  userInfo#3
   在D类执行属性注入时  InjectedElement.inject 从spring中获取bean对象是 beanName 是 AnnotatedFieldElement.injectedObject 的值 
   ![image](https://user-images.githubusercontent.com/32605119/180648633-c911066d-3d7b-4c1a-919d-af4fb930db24.png)
   此时从spring 获取bean的时候 
   ![image](https://user-images.githubusercontent.com/32605119/180648721-b3d7c3dc-7edd-4a9c-a249-923bdcc23ec0.png)
   会从 别名中获取到 真的 注入容器中的那个名称 test test 是UserInfo 类型的, 而D类注入的 类型UserAInfo 
   ![image](https://user-images.githubusercontent.com/32605119/180648852-2a49d1f2-350a-4268-8e07-f7ebb78c83c8.png)
   如图 field 是 UserAInfo injectObject 是 UserInfo类型的 dubbo 代理类,此时类型不匹配 会抛出异常


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