启动时检查
1. 配置介绍
Dubbo 缺省会在启动时检查依赖的服务是否可用,不可用时会抛出异常,阻止 Spring 初始化完成,以便上线时,能及早发现问题,默认 check=“true”。
可以通过 check=“false” 关闭检查,比如,测试时,有些服务不关心,或者出现了循环依赖,必须有一方先启动。
另外,如果你的 Spring 容器是懒加载的,或者通过 API 编程延迟引用服务,请关闭 check,否则服务临时不可用时,会抛出异常,拿到 null 引用,如果 check=“false”,总是会返回引用,当服务恢复时,能自动连上。
2. 测试
2.1 停掉 user服务
2.2 启动order服务
No provider available for the service
com.jxs.interfacedubbo.user.UserService from the url
zookeeper://127.0.0.1:2181/org.apache.dubbo.registry.RegistryService?
application=order-
consumer&dubbo=2.0.2&init=false&interface=com.jxs.interfacedubbo.user.UserS
ervice&methods=getUserList&pid=16672&qos.enable=false®ister.ip=192.168.4
3.242&release=2.7.7&side=consumer&sticky=false&timeout=3000×tamp=16048
22050471 to the consumer 192.168.43.242 use dubbo version 2.7.7
服务启动失败
2.3 增加全局配置
#检查服务提供这个是否存在, true:必须要有服务提供者,否则启动失败,false:不检查服务提供这个,用的时候再检查
dubbo.consumer.check=false
2.3 针对接口配置
@DubboReference(check = false)
private UserService userService;