启动时检查的作用如下:

(1)Dubbo 缺省会在启动时检查依赖的服务是否可用,不可用时会抛出异常,阻止 Spring 初始化完成,以便上线时,能及早发现问题,默认 check="true"

(2)可以通过 check="false" 关闭检查,比如,测试时,有些服务不关心,或者出现了循环依赖,必须有一方先启动的情况下

(3)如果你的 Spring 容器是懒加载的,或者通过 API 编程延迟引用服务,请关闭 check,否则服务临时不可用时,会抛出异常,拿到 null 引用,如果 check="false",总是会返回引用,当服务恢复时,能自动连上。

以前面帖子工程为例:

直接启动服务的消费者:order-service-consumer工程,结果如下:'

具体错误信息如下:提示没有提供者

 Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderServiceImpl': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.lch.test.service.UserService. No provider available for the service com.lch.test.service.UserService from the url zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=order-service-consumer&check=false&dubbo=2.6.2&generic=false&interface=com.lch.test.service.UserService&methods=getUserAddressList&pid=8740&register.ip=192.168.0.110&remote.timestamp=1563206416952&side=consumer&timestamp=1563370847797 to the consumer 192.168.0.110 use dubbo version 2.6.2
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1268)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.lch.test.MainApplication.main(MainApplication.java:12)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.lch.test.service.UserService. No provider available for the service com.lch.test.service.UserService from the url zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=order-service-consumer&check=false&dubbo=2.6.2&generic=false&interface=com.lch.test.service.UserService&methods=getUserAddressList&pid=8740&register.ip=192.168.0.110&remote.timestamp=1563206416952&side=consumer&timestamp=1563370847797 to the consumer 192.168.0.110 use dubbo version 2.6.2
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:177)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1640)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1316)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1282)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
... 15 more
Caused by: java.lang.IllegalStateException: Failed to check the status of the service com.lch.test.service.UserService. No provider available for the service com.lch.test.service.UserService from the url zookeeper://127.0.0.1:2181/com.alibaba.dubbo.registry.RegistryService?anyhost=true&application=order-service-consumer&check=false&dubbo=2.6.2&generic=false&interface=com.lch.test.service.UserService&methods=getUserAddressList&pid=8740&register.ip=192.168.0.110&remote.timestamp=1563206416952&side=consumer&timestamp=1563370847797 to the consumer 192.168.0.110 use dubbo version 2.6.2
at com.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:422)
at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:333)
at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:163)
at com.alibaba.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:66)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:170)
... 25 more

这是因为,如果没有配置启动检查,dubbo是默认进行启动检查的,也就是启动服务的消费者时,先检查服务的提供者有没有启动起来。

修改配置文件,在dubboLreference标签里面加上  check=“false”

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://dubbo.apache.org/schema/dubbo
http://dubbo.apache.org/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"> <!--扫描包注解 -->
<context:component-scan
base-package="com.lch.test.service.impl" /> <!-- 1.消费方应用名 -->
<dubbo:application name="order-service-consumer" /> <!-- 2.指定注册中心地址 -->
<dubbo:registry address="zookeeper://127.0.0.1:2181" /> <!-- 生成远程服务代理dubbo:reference:声明需要调用的远程服务的接口 -->
<!-- user-service-provider工程里面暴露了一个名为userService的服务,这里要引用这个服务 -->
<dubbo:reference id="userService"
26 interface="com.lch.test.service.UserService" check="false"/>
<!-- 连接监控中心:使用自动发现的方式 -->
<dubbo:monitor protocol="register" />
<!-- 直连注册中心 -->
<!-- <dubbo:monitor address="127.0.0.1:7070" /> --> </beans>

然后再启动服务的消费者:

dubbo启动时检查可以配置三种作用范围,上面例子是仅仅关闭对user-service-provider这个服务提供者的检查,如果要关闭所有服务消费者对 与其对应的服务提供者的检查,

可以在标签 dubbo:consumer 中添加check="false" 即:  <dubbo:consumer check="false" />

Dubbo学习-8-dubbo启动时检查的更多相关文章

  1. Dubbo -- 系统学习 笔记 -- 示例 -- 启动时检查

    示例 想完整的运行起来,请参见:快速启动,这里只列出各种场景的配置方式 启动时检查 Dubbo缺省会在启动时检查依赖的服务是否可用,不可用时会抛出异常,阻止Spring初始化完成,以便上线时,能及早发 ...

  2. dubbo启动时检查服务

    Dubbo 缺省会在启动时检查依赖的服务是否可用,不可用时会抛出异常,阻止 Spring 初始化完成,以便上线时,能及早发现问题,默认 check="true". 可以通过 che ...

  3. dubbo之启动时检查

    启动时检查 Dubbo缺省会在启动时检查依赖的服务是否可用,不可用时会抛出异常,阻止Spring初始化完成,以便上线时,能及早发现问题,默认 check="true".所以可以通过 ...

  4. dubbo配置启动时检查

    启动检查设置 Dubbo缺省会在启动时检查依赖的服务是否可用,不可用会抛出异常,阻止Spring初始化完成,默认check="true":是开启检查. 比如测试的时候,有些服务并不 ...

  5. Bubbo的启动时检查

    这个地方参考dubbo的官网,不是很难,为了使得文档的完整,也单独起一章. 1.默认 Dubbo 缺省会在启动时检查依赖的服务是否可用,不可用时会抛出异常,阻止 Spring 初始化完成,以便上线时, ...

  6. Dubbo启动时检查

    Dubbo在启动时会检查服务提供者所提供的服务是否可用,默认为True. (1).单个服务关闭启动时检查(check属性置为false) 1).基于xml文件配置方式 <!--3.声明需要调用的 ...

  7. Dubbo学习(六) dubbo 架构图 以及调用过程

    一.Dubbo结构图   duubo结构图 我们解释以下这个架构图:Consumer服务消费者,Provider服务提供者.Container服务容器.消费当然是invoke提供者了,invoke这条 ...

  8. Dubbo学习(一) Dubbo原理浅析

    一.初入Dubbo Dubbo学习文档: http://dubbo.incubator.apache.org/books/dubbo-user-book/ http://dubbo.incubator ...

  9. Dubbo学习(二) Dubbo 集群容错模式-负载均衡模式

    Dubbo是Alibaba开源的分布式服务框架,我们可以非常容易地通过Dubbo来构建分布式服务,并根据自己实际业务应用场景来选择合适的集群容错模式,这个对于很多应用都是迫切希望的,只需要通过简单的配 ...

随机推荐

  1. AppStore IPv6-only 解决--看我就够了

    自2016年6月1日起,苹果要求所有提交App Store的iOS应用必须支持IPv6-only环境,背景也是众所周知的,IPv4地址已基本分配完毕,同时IPv6比IPv4也更加高效,向IPv6过渡是 ...

  2. tjuthesis 图标题左对齐修改办法

    图标题格式默认是居中的. 将 format 文件里定义图表标题样式部分的 \centering 删去,可变为左对齐. 如下: %% 定制浮动图形和表格标题样式\makeatletter\long\de ...

  3. 职位-CIO:CIO

    ylbtech-职位-CIO:CIO 首席信息官(又称CIO,是Chief Information Officer的缩写)中文意思是首席信息官或信息主管,是负责一个公司信息技术和系统所有领域的高级官员 ...

  4. 术语-BPM:BPM

    ylbtech-术语-BPM:BPM BPM,即业务流程管理,是一种以规范化的构造端到端的卓越业务流程为中心,以持续的提高组织业务绩效为目的的系统化方法,常见商业管理教育如EMBA.MBA等均将BPM ...

  5. oracle查询语句,根据中文的拼音排序

    SELECT * FROM USER t ORDER BY nlssort(FIRSTNAME, 'NLS_SORT=SCHINESE_PINYIN_M')

  6. linux(centos7.0以上)下对mysql数据库的导入导出

    1:查看mysql安装路径: 指令 ps -ef|grep mysql 得出结果 root 968 1 0 18:25 ? 00:00:00 /bin/sh /usr/local/mysql/bin/ ...

  7. Navicat Premium 12.1.20.0安装与激活

    一.Navicat Premium 12下载 链接: https://pan.baidu.com/s/1GgNbCPGahN-Z91f4dnQkBQ 提取码: 3q8f 复制这段内容后打开百度网盘手机 ...

  8. Java 动态代理及AOP实现机制

    AOP实现机制http://www.iteye.com/topic/1116696 AOP: (Aspect Oriented Programming) 面向切面编程AOP包括切面(aspect).通 ...

  9. CentOS7 iptables安装及操作

    添加规则时的考量点: (1)要实现哪种功能:判断添加在哪张表上: (2)报文流经的路径:判断添加在哪个链上: 链上规则的次序: (1)同类规则(访问同一应用),匹配范围小的放上面: (2)不同类规则( ...

  10. Java对象多态性——对象的转型(引用类型之间的类型转换)

    Java引用变量有两个类型:编译时类型和运行时类型.编译时类型由声明该变量时使用的类型决定,运行时类型由实际赋给该变量的对象决定. 若编译时类型和运行时类型不一致,就出现多态 正常的方法调用(本态调用 ...