You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "aishang1993 (via GitHub)" <gi...@apache.org> on 2023/07/01 00:37:57 UTC

[GitHub] [dubbo] aishang1993 opened a new issue, #12637: 3.X ReferenceAnnotationBeanPostProcessor 按@DubboReference属性名注册别名导致异常

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

   - Dubbo version: 3.2.2
   - Java version: 1.8
   - SpringBoot: 2.7.13
   
   [前面也讨论过这个问题](https://github.com/apache/dubbo/issues/10443)
   
   3.X ReferenceAnnotationBeanPostProcessor 按@DubboReference属性名注册别名
   ![image](https://github.com/apache/dubbo/assets/20903014/dc65e128-a484-4980-8e97-101bbfa96584)
   ![image](https://github.com/apache/dubbo/assets/20903014/36a0d6ec-e987-474d-8094-18e18eba893d)
   这样会导致在不同的类中注入不同类型的Bean时必须要用不同的属性名称,如果像下面这样就会导致异常
   ![image](https://github.com/apache/dubbo/assets/20903014/b7271a32-6252-4c79-9710-4366d3fa8849)
   ![image](https://github.com/apache/dubbo/assets/20903014/fb9f7df7-20b7-404c-b2b5-ce4efa5160d2)
   ![image](https://github.com/apache/dubbo/assets/20903014/d7089727-f8e1-4cc5-a5d8-8cd68517c56d)
   **dubbo2.x 就没有这个问题,3.0中使用属性名注册别名是有什么特殊的用意吗?**
   我理解这与spring并没有关系 https://github.com/apache/dubbo/issues/10443#issuecomment-1212703407,
   因为我只要不用 dubbo3.x 就不会导致异常。
   @chickenlj
   
   
   


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


Re: [I] BeanNotOfRequiredTypeException when using spring bean injection [dubbo]

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

   i am new to open sorce contribution 
   so i would like to start from this issue because i know spring 
   can you please guide and assign me to this issue ?


-- 
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 #12637: 3.X ReferenceAnnotationBeanPostProcessor 按@DubboReference属性名注册别名导致异常

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

   可以提供一个能够复现异常的 `demo `么?我这可以正常注入。 使用属性名注册别名 是因为已经有相同类型的bean 被注入到了容器中 且 beanName 不同 才会注册别名


-- 
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] aishang1993 commented on issue #12637: 3.X ReferenceAnnotationBeanPostProcessor 按@DubboReference属性名注册别名导致异常

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

   > 可以提供一个能够复现异常的 `demo `么?我这可以正常注入。 使用属性名注册别名 是因为已经有相同类型的bean 被注入到了容器中 且 beanName 不同 才会注册别名
   
   [demo](https://github.com/aishang1993/dubbo3-fix-12637),这是我复现的demo,Demo2Controller中的demo1Service会导致异常,修改属性名为demo2Service就没问题。
   
   


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


Re: [I] BeanNotOfRequiredTypeException when using spring bean injection [dubbo]

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

   I think I have found what went wrong after finishing several breakpoint tests. Currently, dubbo will register the instance (of the field that is annotated with @DubboReference) into the IoC container, and it uses the **_field's name_** as the bean key by default. For example:
   ```
   public class ControllerA {
        @DubboReference
        public TestService testService;
   }
   ```
   In the above code, dubbo will register **_"testService" --> [TestService bean]_** into the IoC container. This usually works fine, but not for the case when some other places in the project use some code like this:
   ```
   public class ControllerB {
       @Resource
       public Test2Service testService;  // same field name
   }
   ```
   As @liufeiyu1002 said, @ Resource will enable Spring to look for a bean instance in the IoC container **using the field name**. Which means, Spring will detect the existence of **_"testService" --> [TestService bean]_**, find out that TestService (existed bean's class) and Test2Service (the class of the field currently being injected) do not match. That is where an exception is thrown.


-- 
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 #12637: 3.X ReferenceAnnotationBeanPostProcessor 按@DubboReference属性名注册别名导致异常

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

   > > 可以提供一个能够复现异常的 `demo `么?我这可以正常注入。 使用属性名注册别名 是因为已经有相同类型的bean 被注入到了容器中 且 beanName 不同 才会注册别名
   > 
   > [demo](https://github.com/aishang1993/dubbo3-issue-12637),这是我复现的demo,Demo2Controller中的demo1Service会导致异常,修改属性名为demo2Service就没问题。
   
   `@Resource `是 先按照name 查找,找不到再按照类型 查找, 按照你demo 中 `Demo1ServiceImpl` 用 `@service` 注入容器以后 对应的key 为 `demo1ServiceImpl` 在   `@DubboReference  Demo2Service demo1Service;` 注入容器中时 发现 没有 key `demo1Service` 的类型 会使用当前key。  容器执行到属性注入的时候 `@Resource ` 注入的时候 先按照 `name `查询,查找到了Demo2Service  类型注入的那个 bean 导致 赋值的时候 类型不一致报错 
   1. 用 `@autowire` 注解替换 `@resource`
   2. 显示的 指定 service name 
   ```
   @Service("demo1Service")
   public class Demo1ServiceImpl implements Demo1Service
   ```
   同理 不使用dubbo 注解的时候 如果 demo1Service,demo2Service实现声明为 
   ```
   @Service("demo1Service")
   public class Demo1ServiceImpl implements Demo1Service
   @Service
   public class Demo2ServiceImpl implements Demo2Service
   ```
   同时 按照 
   ```
       @Resource
       private Demo1Service demo1Service;
       @Resource
       private Demo2Service demo1Service;
   ```
   注入也会类型异常
   在开发时候 注意规范命名应该可以很大程度避免这种错误


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


Re: [I] BeanNotOfRequiredTypeException when using spring bean injection [dubbo]

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

   ### Experiment
   To try and find a way to fix this issue, I did an experiment. In the following code, the two fields have difference classes but same field names, and they both use @DubboReference for the dependency injection. 
   ```
   public class ControllerA {
       @DubboReference 
       public TestService testService;
   }
   public class ControllerB {
       @DubboReference 
       public Test2Service testService;   // difference class, same field name
   }
   ```
   And dubbo can handle this situation. The first generated bean (assuming it's TestService) is **_"testService" -> [TestService bean]_**, and the second generated bean is **_"testService#2" -> [Test2Service bean]_**. Dubbo slightly changes the latter's bean key to avoid conflicts.
   ![image](https://github.com/apache/dubbo/assets/53827342/87bedf73-7318-431a-bd53-55979e042900)
   ![image](https://github.com/apache/dubbo/assets/53827342/8789af6f-1e7c-4078-a73b-f55c4cb5e5f2)
   
   ### My idea to solve this problem
   So basically, my idea to resolve this issue is that: when we register @DubboReference-annotated bean into Spring IoC container, we shall attach the serial number after its bean key (no matter if it's the first time or not). Applying such an idea to the above code, it will be **_"testService#1" -> [TestService bean]_** and **_"testService#2" -> [Test2Service bean]_**.
   It **probably should be** resolving the problems occurred described by @aishang1993 , because same names of fields may still seem possible, but there is almost no possibility that a field named "XXX#1" will appear in an industry-level project.
   
   Since I am new to the community, I may have overlooked certain important details. Please kindly share your opinions on whether this solution is workable, thanks!


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


Re: [I] BeanNotOfRequiredTypeException when using spring bean injection [dubbo]

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

   Is this issue still open, Can you assign it to me, I'd like to work on this.


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


Re: [I] BeanNotOfRequiredTypeException when using spring bean injection [dubbo]

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

   对比了下2.7.X与3.X   org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor#registerReferenceBean 实现
   同一JVM针对一个接口既是服务提供者又是消费者处理不一样
   2.7.X向spring只注册了服务提供者实例,消费者只注册了别名;
   3.X向spring注册了服务提供者实例,也注册了消费者实例,这样在这个容器Reference,Resource,autowired 注解混用存在很多问题;
   能否参照2.7.X,只注册一个实例,消费者注册别名
   
   ![image](https://github.com/apache/dubbo/assets/12825873/0d623cec-68a7-4917-873c-1b4446c95825)
   


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


Re: [I] BeanNotOfRequiredTypeException when using spring bean injection [dubbo]

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

   I reproduced this on the latest **3.3.6** (release) using the demo from @aishang1993, so this is still unresolved on the current 3.3 line.
   
   **Reproduction** (demo: https://github.com/aishang1993/dubbo3-issue-12637, with 3 adjustments for 3.3.x: bump dubbo.version to 3.3.6, replace the removed `dubbo-dependencies-zookeeper-curator5` pom with `dubbo-registry-zookeeper` + `dubbo-remoting-zookeeper-curator5`, and change `dubbo.protocol.serialization` from `java` to `fastjson2`):
   
   ```
   BeanCreationException: Error creating bean with name 'demo1Controller': Injection of resource dependencies failed;
   Caused by: BeanNotOfRequiredTypeException: Bean named 'demo1Service' is expected to be of type 'com.example.dubbodemo.Demo1Service'
   but was actually of type 'com.example.dubbodemo.Demo2ServiceDubboProxy0'
   ```
   
   **Root cause — a cross-annotation collision that the existing rename guard cannot cover:**
   
   1. `Demo2Controller` has `@DubboReference private Demo2Service demo1Service`. `ReferenceAnnotationBeanPostProcessor.registerReferenceBean` registers a ReferenceBean under the **field name** `demo1Service` (a Demo2Service proxy).
   2. `Demo1Controller` has `@Resource private Demo1Service demo1Service`. `CommonAnnotationBeanPostProcessor` resolves `@Resource` **by name first**, finds the Demo2Service proxy registered above, and the type check fails.
   
   The rename logic in `registerReferenceBean` (3.3 branch, the `rename dubbo reference bean to [xxx#2]` branch) only guards **@DubboReference vs @DubboReference** collisions: it checks `containsBeanDefinition`/aliases at registration time. A `@Resource` field registers no bean definition and is resolved later, so from the processor's point of view the name `demo1Service` was free when `Demo2Controller` was processed — bean-creation order decides which side explodes.
   
   As @huogithub analyzed above, 2.7.x behaved differently in `registerReferenceBean` (provider instance + alias for consumers), which is why this did not happen before 3.x.
   
   **Fix directions — since any naming change is breaking, I'd like the team's preference before writing code:**
   
   1. **Non-breaking mitigation**: when a `@DubboReference`-registered bean name is later resolved by another injector with an incompatible type we cannot intercept Spring's `@Resource` path, so a clean non-breaking fix seems hard. The best non-breaking option I can see is startup-time detection/warning, which only softens the failure.
   2. **Breaking (master/3.4)**: change the default reference bean name for id-less `@DubboReference` from the raw field name to a deterministic name derived from the reference key (interface/group/version), with a compatibility switch (e.g. `dubbo.application.reference-bean-naming-strategy=field-name`) to restore the old behavior.
   
   Happy to implement either — please advise which direction the team prefers. Thanks!


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


Re: [I] BeanNotOfRequiredTypeException when using spring bean injection [dubbo]

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

   could I help out with this? @zeng-bohan gave good solutions, but is this issue inactive, if it is active I would like to help and be assigned


-- 
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 #12637: 3.X ReferenceAnnotationBeanPostProcessor 按@DubboReference属性名注册别名导致异常

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

   Related with https://github.com/apache/dubbo/pull/12474


-- 
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] aishang1993 commented on issue #12637: 3.X ReferenceAnnotationBeanPostProcessor 按@DubboReference属性名注册别名导致异常

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

   > > > 可以提供一个能够复现异常的 `demo `么?我这可以正常注入。 使用属性名注册别名 是因为已经有相同类型的bean 被注入到了容器中 且 beanName 不同 才会注册别名
   > > 
   > > 
   > > [demo](https://github.com/aishang1993/dubbo3-issue-12637),这是我复现的demo,Demo2Controller中的demo1Service会导致异常,修改属性名为demo2Service就没问题。
   > 
   > `@Resource `是 先按照name 查找,找不到再按照类型 查找, 按照你demo 中 `Demo1ServiceImpl` 用 `@service` 注入容器以后 对应的key 为 `demo1ServiceImpl` 在 `@DubboReference Demo2Service demo1Service;` 注入容器中时 发现 没有 key `demo1Service` 的类型 会使用当前key。 容器执行到属性注入的时候 `@Resource ` 注入的时候 先按照 `name `查询,查找到了Demo2Service 类型注入的那个 bean 导致 赋值的时候 类型不一致报错
   > 
   > 1. 用 `@autowire` 注解替换 `@resource`
   > 2. 显示的 指定 service name
   > 
   > ```
   > @Service("demo1Service")
   > public class Demo1ServiceImpl implements Demo1Service
   > ```
   > 
   > 同理 不使用dubbo 注解的时候 如果 demo1Service,demo2Service实现声明为
   > 
   > ```
   > @Service("demo1Service")
   > public class Demo1ServiceImpl implements Demo1Service
   > @Service
   > public class Demo2ServiceImpl implements Demo2Service
   > ```
   > 
   > 同时 按照
   > 
   > ```
   >     @Resource
   >     private Demo1Service demo1Service;
   >     @Resource
   >     private Demo2Service demo1Service;
   > ```
   > 
   > 注入也会类型异常 在开发时候 注意规范命名应该可以很大程度避免这种错误
   
   这个逻辑能理解,但我还是更喜欢2.x那样不会根据属性名去注册别名,这样2.x到3.x升级也会更方便。谢谢你的解答!!!


-- 
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] aishang1993 commented on issue #12637: 3.X ReferenceAnnotationBeanPostProcessor 按@DubboReference属性名注册别名导致异常

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

   > > > > > 可以提供一个能够复现异常的 `demo `么?我这可以正常注入。 使用属性名注册别名 是因为已经有相同类型的bean 被注入到了容器中 且 beanName 不同 才会注册别名
   > > > > 
   > > > > 
   > > > > [demo](https://github.com/aishang1993/dubbo3-issue-12637),这是我复现的demo,Demo2Controller中的demo1Service会导致异常,修改属性名为demo2Service就没问题。
   > > > 
   > > > 
   > > > `@Resource `是 先按照name 查找,找不到再按照类型 查找, 按照你demo 中 `Demo1ServiceImpl` 用 `@service` 注入容器以后 对应的key 为 `demo1ServiceImpl` 在 `@DubboReference Demo2Service demo1Service;` 注入容器中时 发现 没有 key `demo1Service` 的类型 会使用当前key。 容器执行到属性注入的时候 `@Resource ` 注入的时候 先按照 `name `查询,查找到了Demo2Service 类型注入的那个 bean 导致 赋值的时候 类型不一致报错
   > > > 
   > > > 1. 用 `@autowire` 注解替换 `@resource`
   > > > 2. 显示的 指定 service name
   > > > 
   > > > ```
   > > > @Service("demo1Service")
   > > > public class Demo1ServiceImpl implements Demo1Service
   > > > ```
   > > > 
   > > > 
   > > >     
   > > >       
   > > >     
   > > > 
   > > >       
   > > >     
   > > > 
   > > >     
   > > >   
   > > > 同理 不使用dubbo 注解的时候 如果 demo1Service,demo2Service实现声明为
   > > > ```
   > > > @Service("demo1Service")
   > > > public class Demo1ServiceImpl implements Demo1Service
   > > > @Service
   > > > public class Demo2ServiceImpl implements Demo2Service
   > > > ```
   > > > 
   > > > 
   > > >     
   > > >       
   > > >     
   > > > 
   > > >       
   > > >     
   > > > 
   > > >     
   > > >   
   > > > 同时 按照
   > > > ```
   > > >     @Resource
   > > >     private Demo1Service demo1Service;
   > > >     @Resource
   > > >     private Demo2Service demo1Service;
   > > > ```
   > > > 
   > > > 
   > > >     
   > > >       
   > > >     
   > > > 
   > > >       
   > > >     
   > > > 
   > > >     
   > > >   
   > > > 注入也会类型异常 在开发时候 注意规范命名应该可以很大程度避免这种错误
   > > 
   > > 
   > > 这个逻辑能理解,但我还是更喜欢2.x那样不会根据属性名去注册别名,这样2.x到3.x升级也会更方便。谢谢你的解答!!!
   > 
   > 可以试一下 3.2.3 版本是不是还有问题
   
   如果不同类型的成员变量使用相同的属性命名,在3.2.3 版本的异常信息变得准确了。
   
    ```
   Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'demo1Service' is expected to be of type 'com.example.dubbodemo.Demo1Service' but was actually of type 'com.example.dubbodemo.Demo2ServiceDubboProxy0'
    ```


-- 
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 #12637: 3.X ReferenceAnnotationBeanPostProcessor 按@DubboReference属性名注册别名导致异常

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

   > > > > 可以提供一个能够复现异常的 `demo `么?我这可以正常注入。 使用属性名注册别名 是因为已经有相同类型的bean 被注入到了容器中 且 beanName 不同 才会注册别名
   > > > 
   > > > 
   > > > [demo](https://github.com/aishang1993/dubbo3-issue-12637),这是我复现的demo,Demo2Controller中的demo1Service会导致异常,修改属性名为demo2Service就没问题。
   > > 
   > > 
   > > `@Resource `是 先按照name 查找,找不到再按照类型 查找, 按照你demo 中 `Demo1ServiceImpl` 用 `@service` 注入容器以后 对应的key 为 `demo1ServiceImpl` 在 `@DubboReference Demo2Service demo1Service;` 注入容器中时 发现 没有 key `demo1Service` 的类型 会使用当前key。 容器执行到属性注入的时候 `@Resource ` 注入的时候 先按照 `name `查询,查找到了Demo2Service 类型注入的那个 bean 导致 赋值的时候 类型不一致报错
   > > 
   > > 1. 用 `@autowire` 注解替换 `@resource`
   > > 2. 显示的 指定 service name
   > > 
   > > ```
   > > @Service("demo1Service")
   > > public class Demo1ServiceImpl implements Demo1Service
   > > ```
   > > 
   > > 
   > >     
   > >       
   > >     
   > > 
   > >       
   > >     
   > > 
   > >     
   > >   
   > > 同理 不使用dubbo 注解的时候 如果 demo1Service,demo2Service实现声明为
   > > ```
   > > @Service("demo1Service")
   > > public class Demo1ServiceImpl implements Demo1Service
   > > @Service
   > > public class Demo2ServiceImpl implements Demo2Service
   > > ```
   > > 
   > > 
   > >     
   > >       
   > >     
   > > 
   > >       
   > >     
   > > 
   > >     
   > >   
   > > 同时 按照
   > > ```
   > >     @Resource
   > >     private Demo1Service demo1Service;
   > >     @Resource
   > >     private Demo2Service demo1Service;
   > > ```
   > > 
   > > 
   > >     
   > >       
   > >     
   > > 
   > >       
   > >     
   > > 
   > >     
   > >   
   > > 注入也会类型异常 在开发时候 注意规范命名应该可以很大程度避免这种错误
   > 
   > 这个逻辑能理解,但我还是更喜欢2.x那样不会根据属性名去注册别名,这样2.x到3.x升级也会更方便。谢谢你的解答!!!
   
   可以试一下 3.2.3 版本是不是还有问题


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


Re: [I] BeanNotOfRequiredTypeException when using spring bean injection [dubbo]

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

   @AlbumenJ  Hi, I have reproduced this bug in both Dubbo 3.2.2 & 3.2.3, so I'm guessing it's still pending to be fixed. If so, I am interested in solving this issue, please assign it to me :)


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


Re: [I] BeanNotOfRequiredTypeException when using spring bean injection [dubbo]

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

   @AlbumenJ  Is this issue solved or still pending resolution? I have successfully reproduced the reported bug in both 3.2.2 and 3.2.3. If the issue's still open, I am interested in solving it & please assign to me :)


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


Re: [I] BeanNotOfRequiredTypeException when using spring bean injection [dubbo]

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

   Thanks @PrakarshSrivastav — the issue is active. The fix is implemented in #16438: a `dubbo.application.reference-bean-naming-strategy` option that stops `@DubboReference` fields from colliding with `@Resource` by-name lookups. It ships with a test class, CI is green (30/30 checks, 100% patch coverage), and it has been waiting on a maintainer review since 2026-08-26.
   
   The most useful help right now would be **reviewing and testing that PR** rather than starting a parallel implementation:
   
   - Read the approach in #16438 and check it against the Spring injection model. @JerryOops's 2024-03 root-cause analysis above (field-name bean registration colliding with `@Resource`'s by-name lookup) is exactly the behaviour the naming strategy changes, so a second pair of eyes on the default (`field-name`, change is opt-in) would be genuinely valuable.
   - If you use Dubbo in your own project, pull the branch and try your scenario — a "worked for me" with your config is real evidence for the maintainers.
   
   On assignment: only Dubbo committers can assign issues, and since a complete implementation is already up, forking the work would slow this down — reviewing or testing #16438 (or extending it) is the contribution that gets it merged.
   
   @AlbumenJ could you take a look when you have a moment? Happy to adjust the approach based on your feedback.


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