Skip to content

@Reference field can't refer its' @Service Bean in same JVM from v2.6.6 #3695

Closed

Description

@yxc023

Environment

  • Dubbo version: 2.6.6
  • Operating System version: xxx
  • Java version: xxx

Steps to reproduce this issue

  1. xxx
  2. xxx
  3. xxx

Pls. provide [GitHub address] to reproduce this issue.

Expected Result

我用单测实测自己项目内部提供的 dubbo service,

在单测类中使用 @Reference 注解引入服务接口.

启动时报错, 无法获取 provider

Actual Result

在 2.6.5 之前的代码里, 一个项目中的 @Service 和 @Reference 所生成的 bean, 名字都是以 ServiceBean: 开头, 那么在 ReferenceAnnotationBeanPostProcessor.buildInvocationHandler() 中

        if (applicationContext.containsBean(referencedBeanName)) { // Is local @Service Bean or not ?
            // ReferenceBeanInvocationHandler's initialization has to wait for current local @Service Bean has been exported.
            localReferenceBeanInvocationHandlerCache.put(referencedBeanName, handler);
        } else {
            // Remote Reference Bean should initialize immediately
            handler.init();
        }

会进行判断, 如果是内部 service, 则 reference 会等待 service export 之后再 init.

而在 2.6.6 中, 上面代码失效了.

原因在于 2.6.6 使用了 AnnotationBeanNameBuilder 来给 service 和 reference 命名, 化分了不同前缀, 导致同一个项目里 reference 不能等待 service export 之后再去获取.

Activity

  1. yxc023 commented on Mar 19, 2019

    @yxc023
    Author

    可能是个个性化需求, 我先手动 export 解决了.

  2. kexianjun commented on Mar 20, 2019

    @kexianjun
    Member

    I'll try to reproduce this problem

  3. kexianjun commented on Mar 21, 2019

    @kexianjun
    Member

    I have reproduce this issue

  4. cvictory commented on Mar 21, 2019

    @cvictory
    Contributor

    @mercyblitz can you have a look to this issue ?

  5. self-assigned this
    on Mar 21, 2019
  6. added this to the 2.6.7 milestone on Mar 21, 2019
  7. mercyblitz commented on Mar 21, 2019

    @mercyblitz
    Contributor

    This's an issue in 2.6.6

  8. added 2 commits that reference this issue on Jun 25, 2019
  9. added a commit that references this issue on Jun 25, 2019
  10. added a commit that references this issue on Jul 8, 2019
    374d41b
  11. added a commit that references this issue on Jul 9, 2019
  12. added a commit that references this issue on Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions