apache / apache/dubbo

[Bug] When Dubbo is used in conjunction with the Spring container, if the Dubbo generic invocation mode is used and the bean is created using the @bean annotation, it can result in the consumer not being registered as a Spring bean.

Open
#16,083 5 comments 0 reactions 0 assignees View on GitHub
status/waiting-for-feedback
Dominant language
Java
Stars
41.6k
Forks
26.4k
Avg merge
15h 13m
Merged PRs (30d)
4

Description

### Pre-check

- [x] I am sure that all the content I provide is in English.

### Search before asking

- [x] I had searched in the [issues](https://github.com/apache/dubbo/issues?q=is%3Aissue) and found no similar issues.

### Apache Dubbo Component

Java SDK (apache/dubbo)

### Dubbo Version

dubbo-dubbo-3.2.9 open jdk 8

### Steps to reproduce this issue

https://github.com/apache/dubbo/tree/dubbo-3.2.9

### What you expected to happen

When Dubbo is used in conjunction with the Spring container, if the Dubbo generic invocation mode is used and the bean is created using the @bean annotation, it can result in the consumer not being registered as a Spring bean.

For example, when registering a consumer using Dubbo's generic invocation mode, if the @bean annotation is used to create this bean, it can result in the consumer not being registered as a Spring bean.

The reference.get() method returns a proxy object, and the tClass of this proxy object is 'com.xxx.XxxService'.

Image

The reference.get() method returns a proxy object, and the tClass of this proxy object is 'com.xxx.XxxService'. Additionally, this bean is injected using @Autowired and @qualifier as follows:
@Autowired
@qualifier("XxxService")
private GenericService xxxService;

The code for generating a proxy object by Dubbo is as follows: If com.xxx.XxxService exists in the current code package, but reference.setGeneric(true); is still set, it will cause the actual object of the proxy to be com.xxx.XxxService instead of org.apache.dubbo.rpc.service.GenericService.

Image

spring start error text e.g :

Unsatisfied dependency expressed through field 'membershipUserTagTestService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'membershipUserTagTestServiceImpl': Unsatisfied dependency expressed through field 'aeMarketingStrategyShowFacadeGeneric'; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'aeMarketingStrategyShowFacadeGeneric' is expected to be of type 'org.apache.dubbo.rpc.service.GenericService' but was actually of type 'com.sun.proxy.$Proxy524'

### Anything else

_No response_

### Do you have a (mini) reproduction demo?

- [x] Yes, I have a minimal reproduction demo to help resolve this issue more effectively!

### Are you willing to submit a pull request to fix on your own?

- [ ] Yes I am willing to submit a pull request on my own!

### Code of Conduct

- [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)

Contributor guide

Open the contributing guide

Research direction

Start with the dubbo-3.2.9 reproduction and trace the reference.get() path used with reference.setGeneric(true) when the consumer is created through @Bean. Compare the proxy type with GenericService and follow Spring's @Autowired/@Qualifier bean registration path. Done means the generic consumer is registered with the expected type and application startup no longer raises BeanNotOfRequiredTypeException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.