Closed yuxiao97 closed 3 years ago
I reference dubbo service in same JavaConfig class, then @Autowired in used class, but in used class tips no beans found of the type, even I use interfaceName in @DubboReference and use @Qualifier, the same result with before.
I reference dubbo service in same JavaConfig class, then @Autowired in used class, but in used class tips no beans found of the type, even I use interfaceName in @DubboReference and use @Qualifier, the same result with before.
When use JavaConfig then start failed:
Field AAAService in BBBServiceImpl required a bean of type 'AAAService' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
This is an annoying behavior.
Since 2.7.5 (maybe), @DubboReference
cache the generated stub and register into spring application context.
But, if you do this in the @Configuration
class, will break the dependency graph, because there is no @Bean
method to tell spring should initialize the java config class before your service class.
To solve this problem, temporary, should put a @DependsOn("javaConfigClassBeanName")
onto you service class to fix the broken dependency graph.
However, this solution is not elegant enough. The best way is separate dubbo reference declaration and injection.
I use JavaConfig as SpringBean, than use @DubboReference reference Dubbo service and declcare Dubbo service as Bean, like this:
@Configuration
public class DubboServiceReferenceConfig {
@DubboReference(version = "${dubbo.application.version}", check = false)
private UserInfoService userInfoService;
@Bean
public UserInfoService userInfoService() {
return userInfoService;
}
}
Environment
Steps to reproduce this issue
How to use @DubboReference annotations Like xml, the basic attributes are only configured once, instead of configuring the same attributes for each reference.