No provider available from registry localhost:9090 问题记录

2,633 阅读2分钟

「这是我参与11月更文挑战的第7天,活动详情查看:2021最后一次更文挑战」。

记录下使用spring-cloud-alibaba 遇到的问题,这个问题前几天终于解决了。

问题描述

现在项目使用spring-cloud-alibaba框架,具体版本如下

  • Spring Cloud 2020.0.1,
  • Spring Boot 2.4.2,
  • Spring Cloud Alibaba 2021.1

今天我们要加入dubbo 调用。于是乎,参考文档写

# 其中子属性 address 的值 “spring-cloud://localhost”,说明挂载到 Spring Cloud 注册中心
 这个 挂载到springcloud 注册中心
dubbo.registry.address=spring-cloud://localhost

然后启动项目,项目报错如下

2021-11-11 08:27:40.551 [mainraceId] ERROR [main] org.springframework.boot.SpringApplication - Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'noteController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'noteServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'noteManagerImpl': Injection of @DubboReference dependencies is failed; nested exception is java.lang.IllegalStateException: Failed to check the status of the service com.qlteacher.service.NotePublicService. No provider available for the service com.qlteacher.service.NotePublicService from the url spring-cloud://localhost:9090/org.apache.dubbo.registry.RegistryService?application=learning&dubbo=2.0.2&init=false&interface=com.qlteacher.service.NotePublicService&methods=editNoteLikeCount,addNote,gatherNoteCount,editNote,queryNoteList,editNotePublic,removeNote&pid=10524&qos.enable=false&register.ip=192.168.100.61&release=2.7.8&revision=1.0.12&side=consumer&sticky=false&timestamp=1636590460047 to the consumer 192.168.100.61 use dubbo version 2.7.8
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:321) ~[spring-context-5.3.3.jar:5.3.3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1415) ~[spring-beans-5.3.3.jar:5.3.3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:608) ~[spring-beans-5.3.3.jar:5.3.3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.3.jar:5.3.3]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.3.jar:5.3.3]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.3.jar:5.3.3]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.3.jar:5.3.3]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.3.jar:5.3.3]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.3.jar:5.3.3]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:923) ~[spring-context-5.3.3.jar:5.3.3]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:588) ~[spring-context-5.3.3.jar:5.3.3]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.2.jar:2.4.2]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[spring-boot-2.4.2.jar:2.4.2]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.4.2.jar:2.4.2]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.2.jar:2.4.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.2.jar:2.4.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) ~[spring-boot-2.4.2.jar:2.4.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) ~[spring-boot-2.4.2.jar:2.4.2]
	at com.qlteacher.RunLearning.main(RunLearning.java:21) ~[main/:?]

寻找答案1

这时的我慌了,不能dubbo调用,怎么和上面交差啊,于是我就去 github 上的 Issues 上寻找答案: No provider available from registry localhost:9090 for service xxx/com.alibaba.cloud.dubbo.service.DubboMetadataService:1.0.0 on consumer 172.26.160.1 use dubbo version 2.7.8, please check status of providers(disabled, not registered or in blacklist). · Issue #2274 · alibaba/spring-cloud-alibaba (github.com)

下面的答案也是无解

于是我又找,终于找到了解决办法

dubbo.registry.address=nacos://ip:8848

果然,尝试是好的,于是乎我理所当然的认为当前已经解决问题了

寻找答案2

时间过去了好几周了,就在上周,我试试用feign调用:具体见上篇文章。一开始 也是不行。于是我又各种网上搜,忽然看到一篇文章里面写着看看 nacos注册是否在一个namespace下,是否在一个group里。

我看了看 nacos,发现了问题,我2个服务在一个namespace里面,但是不在一个group里,于是我把所有的group都删除了,于是所有都默认DEFAULT_GROUP 组。

果然,好了

于是,我就想到了之前的那个问题,想着是不是这个问题导致的,于是改回

dubbo.registry.address=spring-cloud://localhost

见证奇迹的时刻

好了!

内心无比激动啊,当时。

总结

问题解决了,说明这个问题还是自己使用nacos没有完全理解的去使用了。如果你也遇到这个问题了,亲 抓紧改改吧