Apache Dubbo使用遇到问题记录(二)

3,201 阅读1分钟

问题三

描述

服务消费方项目在服务提供方项目未启动情况下,启动报错:

2021-03-23 17:51:28.610 ERROR 15728 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testConsumerProviderServiceController': Unsatisfied dependency expressed through field 'remoteProviderService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'remoteProviderServiceImpl': Injection of @DubboReference dependencies is failed; nested exception is java.lang.IllegalStateException: Failed to check the status of the service org.example.common.service.ProviderService. No provider available for the service org.example.common.service.ProviderService from the url registry://localhost:9090/org.apache.dubbo.registry.RegistryService?application=consumer&dubbo=2.0.2&init=false&interface=org.example.common.service.ProviderService&metadata-type=remote&methods=test&pid=15728&qos.accept.foreign.ip=false&qos.enable=false&register.ip=192.168.0.168&registry=spring-cloud&release=2.7.8&side=consumer&sticky=false&timeout=10000&timestamp=1616493088059 to the consumer 192.168.0.168 use dubbo version 2.7.8
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1420) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE]
	at com.example.consumer.ConsumerBootstrap.main(ConsumerBootstrap.java:14) [main/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'remoteProviderServiceImpl': Injection of @DubboReference dependencies is failed; nested exception is java.lang.IllegalStateException: Failed to check the status of the service org.example.common.service.ProviderService. No provider available for the service org.example.common.service.ProviderService from the url registry://localhost:9090/org.apache.dubbo.registry.RegistryService?application=consumer&dubbo=2.0.2&init=false&interface=org.example.common.service.ProviderService&metadata-type=remote&methods=test&pid=15728&qos.accept.foreign.ip=false&qos.enable=false&register.ip=192.168.0.168&registry=spring-cloud&release=2.7.8&side=consumer&sticky=false&timeout=10000&timestamp=1616493088059 to the consumer 192.168.0.168 use dubbo version 2.7.8
	at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor.postProcessPropertyValues(AbstractAnnotationBeanPostProcessor.java:149) ~[spring-context-support-1.0.10.jar:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1425) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	... 20 common frames omitted
Caused by: java.lang.IllegalStateException: Failed to check the status of the service org.example.common.service.ProviderService. No provider available for the service org.example.common.service.ProviderService from the url registry://localhost:9090/org.apache.dubbo.registry.RegistryService?application=consumer&dubbo=2.0.2&init=false&interface=org.example.common.service.ProviderService&metadata-type=remote&methods=test&pid=15728&qos.accept.foreign.ip=false&qos.enable=false&register.ip=192.168.0.168&registry=spring-cloud&release=2.7.8&side=consumer&sticky=false&timeout=10000&timestamp=1616493088059 to the consumer 192.168.0.168 use dubbo version 2.7.8
	at org.apache.dubbo.config.ReferenceConfig.checkInvokerAvailable(ReferenceConfig.java:420) ~[dubbo-2.7.8.jar:2.7.8]
	at org.apache.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:315) ~[dubbo-2.7.8.jar:2.7.8]
	at org.apache.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:205) ~[dubbo-2.7.8.jar:2.7.8]
	at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:144) ~[dubbo-2.7.8.jar:2.7.8]
	at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor.getInjectedObject(AbstractAnnotationBeanPostProcessor.java:362) ~[spring-context-support-1.0.10.jar:na]
	at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor$AnnotatedFieldElement.inject(AbstractAnnotationBeanPostProcessor.java:542) ~[spring-context-support-1.0.10.jar:na]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor.postProcessPropertyValues(AbstractAnnotationBeanPostProcessor.java:145) ~[spring-context-support-1.0.10.jar:na]
	... 31 common frames omitted

2021-03-23 17:51:28.612  INFO 15728 --- [Report-thread-1] c.a.n.client.config.NacosConfigService   : [fixed-127.0.0.1_8848] [publish-single] ok, dataId=org.example.common.service.ProviderService:::consumer:consumer, group=dubbo, tenant=, config={"init":"false","side":"consumer","metadata-type":"remote","application":"consumer","release":"2.7.8...

原因

对于服务消费方而言,所需服务未启动,消费方的启动将一直卡在对服务的检查和重试中。

解决方法

方法一

为@DubboReference注解添加参数配置如下:

@Service
public class RemoteProviderServiceImpl implements RemoteProviderService {
    public static final Logger logger = LoggerFactory.getLogger(RemoteProviderServiceImpl.class);
    @DubboReference(retries = 0,check = false)
    private ProviderService providerService;

    @Override
    public String testRemoteProviderService() {
        logger.info("消费方开始进行消费=======");
        return providerService.test();
    }
}
方法二(推荐)

在项目配置文件中指定dubbo.consumer.check配置

dubbo.consumer.check=false