Spring Cloud + Nacos + Dubbo 整合失败

Bug 描述

Spring Cloud + Nacos + Dubbo 启动错误; 我自己来看,nacos配置中心的配置是读取到了,但是不知道是我配置的问题还是什么,dubbo启动失败

环境

image.png image.png

期望结果

启动 provider 及 consumer 并完成调用

错误信息

部分错误信息,网上找了没找到解决方案

text
复制代码
2024-08-02T22:12:28.816+08:00 INFO 13492 --- [provider] [ main] org.apache.dubbo.config.ServiceConfig : [DUBBO] Register dubbo service cn.cutepikachu.demo.ExampleService url dubbo://26.26.26.1:20880/cn.cutepikachu.demo.ExampleService?anyhost=true&application=provider&background=false&bind.ip=26.26.26.1&bind.port=20880&deprecated=false&dubbo=2.0.2&dynamic=true&executor-management-mode=isolation&file-cache=true&generic=false&interface=cn.cutepikachu.demo.ExampleService&methods=sayHello&pid=13492&prefer.serialization=fastjson2,hessian2&release=3.2.14&service-name-mapping=true&side=provider&timestamp=1722607948062 to registry 127.0.0.1:8848, dubbo version: 3.2.14, current host: 26.26.26.1 2024-08-02T22:12:28.817+08:00 ERROR 13492 --- [provider] [ main] o.a.d.c.deploy.DefaultModuleDeployer : [DUBBO] Model start failed: Dubbo Module[1.1.1] start failed: java.lang.IllegalStateException: No such extension org.apache.dubbo.registry.RegistryFactory by name dubbo, no related exception was found, please check whether related SPI module is missing., dubbo version: 3.2.14, current host: 26.26.26.1, error code: 5-14. This may be caused by , go to https://dubbo.apache.org/faq/5/14 to find instructions. java.lang.IllegalStateException: No such extension org.apache.dubbo.registry.RegistryFactory by name dubbo, no related exception was found, please check whether related SPI module is missing. 2024-08-02T22:12:28.821+08:00 WARN 13492 --- [provider] [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: java.lang.IllegalStateException: No such extension org.apache.dubbo.registry.RegistryFactory by name dubbo, no related exception was found, please check whether related SPI module is missing.

自己的思路和解决方案

详细列举自己的思路、排查过程,以及尝试过的所有解决方法。

比如是否搜索过?搜索的关键词是什么?阅读过哪些文档?

相关资料

Interface 模块

java
复制代码
public interface ExampleService { String sayHello(String name); }

Provider 模块

yml
复制代码
# bootstrap.yml server: port: 6001 spring: application: name: @artifactId@ cloud: nacos: config: server-addr: ${NACOS_HOST:127.0.0.1}:${NACOS_PORT:8848} file-extension: yml namespace: @nacos.namespace@ shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} username: nacos password: nacos discovery: server-addr: ${spring.cloud.nacos.config.server-addr} username: ${spring.cloud.nacos.config.username} password: ${spring.cloud.nacos.config.password} profiles: active: @profiles.active@
java
复制代码
@DubboService public class ExampleServiceImpl implements ExampleService { @Override public String sayHello(String name) { return "Hello, " + name + "!"; } }
java
复制代码
@EnableDubbo @EnableDiscoveryClient @SpringBootApplication public class ProviderApplication { public static void main(String[] args) { SpringApplication.run(ProviderApplication.class, args); } }

Consumer 模块

yml
复制代码
# bootstrap.yml server: port: 6002 spring: application: name: @artifactId@ cloud: nacos: config: server-addr: ${NACOS_HOST:127.0.0.1}:${NACOS_PORT:8848} file-extension: yml namespace: @nacos.namespace@ shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} username: nacos password: nacos discovery: server-addr: ${spring.cloud.nacos.config.server-addr} username: ${spring.cloud.nacos.config.username} password: ${spring.cloud.nacos.config.password} profiles: active: @profiles.active@
java
复制代码
@RestController("/example") public class ExampleController { @DubboReference private ExampleService exampleService; @GetMapping("/hello") public String hello(@RequestParam String name) { return exampleService.sayHello(name); } }
java
复制代码
@EnableDubbo @EnableDiscoveryClient @SpringBootApplication public class ConsumerApplication { public static void main(String[] args) { SpringApplication.run(ConsumerApplication.class, args); } }

nacos 配置中心远程配置

image.png
yml
复制代码
spring: profiles: active: dev dubbo: protocol: name: dubbo port: -1 registry: address: ${spring.cloud.nacos.config.server-addr} # username: ${spring.cloud.nacos.config.username} # password: ${spring.cloud.nacos.config.password}
0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
下载 APP