dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

Fix issue 16083: Consumer is not registered as a Spring bean when the Dubbo generic invocation mode is used and the consumer is created with ```@Bean``` annotation

Open ban-xiu opened this issue 8 months ago • 7 comments

What is the purpose of the change?

Close https://github.com/apache/dubbo/issues/16083

Checklist

  • [x] Make sure there is a GitHub_issue field for the change.
  • [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • [x] Write necessary unit-test to verify your logic correction. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • [x] Make sure gitHub actions can pass. Why the workflow is failing and how to fix it?

ban-xiu avatar Mar 16 '26 07:03 ban-xiu

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 60.90%. Comparing base (5553cb7) to head (a8a3efc).

Additional details and impacted files
@@            Coverage Diff            @@
##                3.3   #16144   +/-   ##
=========================================
  Coverage     60.90%   60.90%           
+ Complexity    11765    11764    -1     
=========================================
  Files          1953     1953           
  Lines         89271    89271           
  Branches      13473    13473           
=========================================
+ Hits          54367    54373    +6     
+ Misses        29321    29318    -3     
+ Partials       5583     5580    -3     
Flag Coverage Δ
integration-tests-java21 32.13% <100.00%> (-0.01%) :arrow_down:
integration-tests-java8 32.21% <100.00%> (+<0.01%) :arrow_up:
samples-tests-java21 32.13% <80.00%> (-0.03%) :arrow_down:
samples-tests-java8 29.73% <80.00%> (-0.09%) :arrow_down:
unit-tests-java11 59.17% <100.00%> (+<0.01%) :arrow_up:
unit-tests-java17 58.63% <100.00%> (-0.02%) :arrow_down:
unit-tests-java21 58.63% <100.00%> (-0.01%) :arrow_down:
unit-tests-java25 58.60% <100.00%> (-0.01%) :arrow_down:
unit-tests-java8 59.16% <100.00%> (-0.02%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov-commenter avatar Mar 16 '26 08:03 codecov-commenter

In this mode, ensure that invoker.getInterface() (i.e., GenericService) is placed at the forefront.

ban-xiu avatar Mar 16 '26 11:03 ban-xiu

this pr might cause problem if the dubbo generice service references are created without annotation @Bean. Dubbo registers reference beans into the Spring container automatically no matter using annotation @Bean or not.

zrlw avatar Mar 17 '26 09:03 zrlw

this pr might cause problem if the dubbo generice service references are created without annotation @Bean. Dubbo registers reference beans into the Spring container automatically no matter using annotation @Bean or not.

It seems that the only scenario where the interface order of AbstractProxyFactory needs to take effect for Spring is when users entirely bypass ReferenceBean and directly call referenceConfig.get() in a @Bean method—which is precisely the case this PR aims to fix.

ban-xiu avatar Mar 17 '26 12:03 ban-xiu

It seems that scenarios without @Bean won't cause issues either, because those cases are protected by the lazy proxy layer.

ban-xiu avatar Mar 17 '26 12:03 ban-xiu

@zrlw I looked into this concern. This change only reorders two code blocks — the final set of interfaces the proxy implements stays exactly the same, just the iteration
order in LinkedHashSet changes.

My understanding is that for references created without @Bean (via @DubboReference or XML), Spring resolves bean type through ReferenceBean.getObjectType(), which returns interfaceClass directly and doesn't depend on proxy interface order. So I think this change should not affect those scenarios. But please correct me if I'm
missing something here.

As for why the reorder helps the @Bean case: Javassist Proxy.getProxy() uses ics[0].getClassLoader() to create the proxy class. Before this change, ics[0] was the
user's business interface (e.g. com.xxx.XxxService), whose classloader might not be compatible with GenericService. After this change, ics[0] becomes GenericService, and its classloader (Dubbo's classloader) generally has better visibility.

Would love to hear your thoughts — happy to adjust the approach if there are cases I haven't considered.

ban-xiu avatar Mar 26 '26 12:03 ban-xiu

@AlbumenJ PTAL

zrlw avatar Jun 30 '26 02:06 zrlw