ReferenceAnnotationBeanPostProcessor registerReferenceBean 判断beanName重复问题 导致启动失败
- [x] I have searched the issues of this repository and believe that this is not a duplicate.
Environment
- Dubbo version: 3.0.10
- Operating System version: Mac 11.6
- Java version: 1.8.0_221
Steps to reproduce this issue
DemoService 有 DemoServiceImpl 实现 是 @DubboService ,
TestService 由 TestServiceImpl 实现 是普通的 @Service

并在两个不同的地方 用@DubboReference 和 @Resource 引用 ,用相同的beanName 都写为 testService

Actual Behavior
- 启动后报错
Description:
The bean 'testService' could not be injected as a 'org.apache.dubbo.springboot.demo.consumer.TestService' because it is a JDK dynamic proxy that implements:
Action:
Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.
-
如果 TestService 不是 由 TestServiceImpl 实现 的接口,而是直接是 @Service 类 则不报错

-
如果 TestService 的实现 是 @DubboService 且引用的地方是 @DubboReference 也不会报错

7.目测是 check bean definition ReferenceAnnotationBeanPostProcessor
401 行 beanDefinitionRegistry.containsBeanDefinition(referenceBeanName) 判断有一定的问题

8.目前只能命名规范,让它不相同 。
If there is an exception, please attach the exception trace:
Just put your stack trace here!
看了下 和 https://github.com/apache/dubbo/issues/10335 类似 ,但感觉不是相同的问题,如果TestService 是 dubboService 的话我这里是能启动成功的。
@DubboReference 是按照属性名称注入 spring 容器中的,在beanFactory中是 属性名称 对应 beanDefinition
使用 @Autowire 不会出现该错误 因为是 byType 注入按照实例类型查找的,
@Resource 是 byName 按照属性名称注入,, 在查找的时候通过 属性名称 匹配,如果匹配到就会拿对应的实例注入,不校验类型。这些都是spring相关的
我觉得这个不应该是 dubbo 的 bug,如果你的 DemoServiceImpl 在 consumer项目中 且 手动指定了@service("testService") 同样会报错,和 dubbo 无关
这是个问题,我们在升级到 Dubbo3 的过程中,很多很多服务遇到了这个问题,改起来非常麻烦,几乎得把所有的 @Resource 全部改成 @Autowired,影响面非常大,所有服务都得做回归测试。
@liufeiyu1002 Dubbo 做出了这些改动要充分考虑到影响,为什么没有其他的框架有类似的问题。而且这个问题出的很诡异,报的错和 Dubbo 无关,是什么「JDK dynamic proxy that implements」,网上搜到的都是错误答案。我们排查了几天,一步步跟进 Spring 对 Bean 处理的地方,最终才定位到 Dubbo3 身上。
建议重开这个 issue 充分讨论,我也将再提个新的 issue。
这个本身就是 对spring 使用的问题 是 @resource 和 @autowired 的区别,可以看下 dubbo 2.x @Reference 注入spring容器 时的beanname, 你也可以 提下你的 issue 问题看一下
需要替换未 autowired 大多是因为不同类型 属性名称重复使用