环境
spring boot 2.1.1.RELEASE
dubbo version 2.7.3
现象
Dubbo服务有依赖时,如A依赖B。B依赖C,那必须要按顺序先启动C,再启动B,最后再启动A。不然A,B都无法启动。会报错Injection of @Reference dependencies is failed;
导致应用无法启动。
2019-12-05 11:18:16.294 ERROR 3668 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of @Reference dependencies is failed; nested exception is java.lang.IllegalStateException: Failed to check the status of the service org.nacosdemo.account.service.AccountService. No provider available for the service org.nacosdemo.account.service.AccountService from the url spring-cloud://localhost:9090/org.apache.dubbo.registry.RegistryService?application=service-user&dubbo=2.0.2&interface=org.nacosdemo.account.service.AccountService&lazy=false&methods=selectAll,selectById,updateBalance&pid=3668&qos.enable=false®ister.ip=10.53.56.1&release=2.7.3&retries=0&side=consumer&sticky=false×tamp=1575515895860 to the consumer 10.53.56.1 use dubbo version 2.7.3
at org.apache.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.postProcessPropertyValues(AnnotationInjectedBeanPostProcessor.java:151) ~[dubbo-2.7.3.jar:2.7.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1383) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
解决方法
在@Reference注解上添加check=false属性即可
public class UserController {
private static Logger logger = LoggerFactory.getLogger(UserController.class);
@Autowired
private UserService userService;
@Reference(retries = 0, check = false)
private AccountService accountService;