apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.36k stars 26.41k forks source link

Autowired a ReferenceBean failed in some situation in Spring enviroment. #6000

Open anLA7856 opened 4 years ago

anLA7856 commented 4 years ago

Environment

Steps to reproduce this issue

In daily development, I am used to keeping Dubbo reference bean in Spring container. Like using xml config, I will write all reference bean in a config class, and use @Autowire in other class. Sometime it runs well, sometime it will throw NoSuchBeanDefinitionException. Problem Description: My project tree(Consumer side):

│  Consumer.java
├─aaconfig
│      MyPriorityReferenceConfig.java
├─adubbo
│      HelloDubbo.java
└─dubbo
       MyReferenceConfig.java

I have two config file. MyReferenceConfig.java and MyPriorityReferenceConfig.java have the same code.

@Configuration
public class XXX {
    @Reference(version = "1.0.0", check = false)
    HelloService helloService;
}

HelloDubbo.java contains an annotation field(@Autowired or @Resource).

@Component
public class HelloDubbo {
    HelloService helloService;
    @Resource
    public void setHelloService(HelloService helloService) {
        this.helloService = helloService;
    }
}

When there is only MyReferenceConfig.java be register in Spring Context. It will throw an Exception:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xxx.rpc.configcenter.provider.service.HelloService'

However, When only MyPriorityReferenceConfig.java be register in Spring Context. It will found that bean successfully.

Expected Result

No Exception

Actual Result

throw a NoSuchBeanDefinitionException

nickwongwong commented 3 years ago

Same problem~

kylixs commented 3 years ago

This bug has been fixed: https://github.com/apache/dubbo/pull/7383