Dubbo学习-8-dubbo启动时检查

启动时检查的作用如下:
(1)Dubbo 缺省会在启动时检查依赖的服务是否可用,不可用时会抛出异常,阻止 Spring 初始化完成,以便上线时,能及早发现问题,默认 check="true"
(2)可以通过 check="false" 关闭检查,比如,测试时,有些服务不关心,或者出现了循环依赖,必须有一方先启动的情况下
(3)如果你的 Spring 容器是懒加载的,或者通过 API 编程延迟引用服务,请关闭 check,否则服务临时不可用时,会抛出异常,拿到 null 引用,如果 check="false",总是会返回引用,当服务恢复时,能自动连上。
以前面帖子工程为例:
直接启动服务的消费者:order-service-consumer工程,结果如下:'
Dubbo学习-8-dubbo启动时检查
文章图片


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

1 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®ister.ip=192.168.0.110&remote.timestamp=1563206416952&side=consumer×tamp=1563370847797 to the consumer 192.168.0.110 use dubbo version 2.6.2 2at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) 3at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) 4at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) 5at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1268) 6at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) 7at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) 8at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) 9at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 10at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) 11at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 12at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) 13at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) 14at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) 15at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) 16at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83) 17at com.lch.test.MainApplication.main(MainApplication.java:12) 18 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®ister.ip=192.168.0.110&remote.timestamp=1563206416952&side=consumer×tamp=1563370847797 to the consumer 192.168.0.110 use dubbo version 2.6.2 19at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:177) 20at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103) 21at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1640) 22at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254) 23at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) 24at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) 25at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1316) 26at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1282) 27at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101) 28at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) 29at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) 30... 15 more 31 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®ister.ip=192.168.0.110&remote.timestamp=1563206416952&side=consumer×tamp=1563370847797 to the consumer 192.168.0.110 use dubbo version 2.6.2 32at com.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:422) 33at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:333) 34at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:163) 35at com.alibaba.dubbo.config.spring.ReferenceBean.getObject(ReferenceBean.java:66) 36at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:170) 37... 25 more

这是因为,如果没有配置启动检查,dubbo是默认进行启动检查的,也就是启动服务的消费者时,先检查服务的提供者有没有启动起来。
修改配置文件,在dubboLreference标签里面加上check=“false”
1 2 12 13 14 16 17 18 19 20 21 22 23 24 25 27 28 29 30 31 32 33 34

然后再启动服务的消费者:
Dubbo学习-8-dubbo启动时检查
文章图片



【Dubbo学习-8-dubbo启动时检查】 dubbo启动时检查可以配置三种作用范围,上面例子是仅仅关闭对user-service-provider这个服务提供者的检查,如果要关闭所有服务消费者对 与其对应的服务提供者的检查,
可以在标签 dubbo:consumer 中添加check="false" 即:
Dubbo学习-8-dubbo启动时检查
文章图片

转载于:https://www.cnblogs.com/enjoyjava/p/11203975.html

    推荐阅读