Why <dubbo:referende> or @Reference cannot exist as a Spring Bean to avoid @Autowired errors in the IDEA?
- [x] I have searched the issues of this repository and believe that this is not a duplicate.
- [x] I have checked the FAQ of this repository and believe that this is not a duplicate.
Environment
- Dubbo version: 2.6.0
- Operating System version: windows 10
- Java version: 1.8
Steps to reproduce this issue
1:Config dubbo:refrence; 2:@Autowired dubbo:refrence Service in Service
Expected Result
I hope this way above can avoid IDEA can not found xxx Beans errors.
Because of @Reference supports the customized behavior for Dubbo Service, for example:
@Reference
private UserService userService;
@Reference(protocol="dubbo")
private UserService userService;
If the above two fields will be enhanced as the Spring Beans, the problem is how to identify them.
Because of
@Referencesupports the customized behavior for Dubbo Service, for example:@Reference private UserService userService; @Reference(protocol="dubbo") private UserService userService;If the above two fields will be enhanced as the Spring Beans, the problem is how to identify them.
OK, I know you means, if as the Spring Bean, Spring can not found and initialize them.
Because of
@Referencesupports the customized behavior for Dubbo Service, for example:@Reference private UserService userService; @Reference(protocol="dubbo") private UserService userService;If the above two fields will be enhanced as the Spring Beans, the problem is how to identify them.
OK, I know you means, if as the Spring Bean, Spring can not found and initialize them.
Thus, Dubbo will provide a new mechanism that @Reference enhances a Spring Bean whose name will be associated with name() attribute, and the Client @Autowired that bean, for example:
@Configuration
public class SomeConfiguration {
@Reference(name="userService")
private UserService userService;
@Reference(name="userService2", protocol="dubbo")
private UserService userService2;
...
}
@RestController
public Class UserController {
@Autowired
@Qualifier("userService")
private UserService userService;
@Autowired
@Qualifier("userService2")
private UserService userService2;
}
Because of
@Referencesupports the customized behavior for Dubbo Service, for example:@Reference private UserService userService; @Reference(protocol="dubbo") private UserService userService;If the above two fields will be enhanced as the Spring Beans, the problem is how to identify them.
OK, I know you means, if as the Spring Bean, Spring can not found and initialize them.
Thus, Dubbo will provide a new mechanism that
@Referenceenhances a Spring Bean whose name will be associated withname()attribute, and the Client@Autowiredthat bean, for example:@Configuration public class SomeConfiguration { @Reference(name="userService") private UserService userService; @Reference(name="userService2", protocol="dubbo") private UserService userService2; ... }@RestController public Class UserController { @Autowired @Qualifier("userService") private UserService userService; @Autowired @Qualifier("userService2") private UserService userService2; }
Thanks, expected the function realization!
expect
expect
It works since 2.7.3!
It works since 2.7.3!
I test on 2.7.7, not worked yet, code like this:
@Configuration
public class SomeConfiguration {
@DubboReference(version="xxx", protocol="dubbo",check=false)
private UserService userService;
...
}
@Service
public Class OtherService {
@Autowired
private UserService userService;
...
}
Happened error
Field UserService in OtherService required a bean of type UserService that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
when start server.
It works since 2.7.3!
I test on 2.7.7, not worked yet, code like this:
@Configuration public class SomeConfiguration { @DubboReference(version="xxx", protocol="dubbo",check=false) private UserService userService; ... } @Service public Class OtherService { @Autowired private UserService userService; ... }Happened error
Field UserService in OtherService required a bean of type UserService that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)when start server.
Test on local DEV is OK, local environment Mac OS 10.15.6, jdk8. Server environment CentOS Linux release 7.4.1708 (Core),jdk8
It works since 2.7.3!
I test on 2.7.7, not worked yet, code like this:
@Configuration public class SomeConfiguration { @DubboReference(version="xxx", protocol="dubbo",check=false) private UserService userService; ... } @Service public Class OtherService { @Autowired private UserService userService; ... }Happened error
Field UserService in OtherService required a bean of type UserService that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)when start server.
Test on local DEV is OK, local environment Mac OS 10.15.6, jdk8. Server environment CentOS Linux release 7.4.1708 (Core),jdk8
Same confusing problem. Ok in local, Broken in server.
Have a try at this: `@Configuration public class DubboConfig {
@Reference
private DemoServie demoService;
@Bean
public DemoServie demoServie() {
return demoService;
}
}`
Have a try at this: `@Configuration public class DubboConfig {
@Reference private DemoServie demoService; @Bean public DemoServie demoServie() { return demoService; }}`
Yes, I use the same as yours, and you can also use the following methods on 2.7.8
@DubboReference(protocol = "dubbo", check = false, timeout = 5000, retries = 1)
public DemoService setDemoService(DemoService demoService){
return demoService;
}