apache / apache/dubbo

Autowired a ReferenceBean failed in some situation in Spring enviroment.

Open
#6,000 2 comments 0 reactions 1 assignee Claimed by @kylixs View on GitHub
Dominant language
Java
Stars
41.6k
Forks
26.4k
Avg merge
15h 13m
Merged PRs (30d)
4

Description

- [x] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
- [x] I have checked the [FAQ](https://github.com/apache/dubbo/blob/master/FAQ.md) of this repository and believe that this is not a duplicate.

### Environment

* Dubbo version: 2.7.3 ~
* Operating System version: linux & windows
* Java version: 1.8

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.