由于工作使用的是HSF,所以最近就自己研究下学习dubbo框架,采用当前主流的spring boot 集成 dubbo,学习过程中遇到了几个问题,在此记录下,希望可以帮到同样遇到问题的你。
问题1.The bean ‘dubboConfigConfiguration.Single’ could not be registered. A bean with that name has already been defined and overriding is disabled.
Description:
The bean 'dubboConfigConfiguration.Single' could not be registered. A bean with that name has already been defined and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
问题1简单来说就是服务启动时bean的名字被定义了多个,而且不能被重写,解决方法其实在报错信息里面也给出了:
解决方案:
在application.properties配置文件中添加以下配置
spring.main.allow-bean-definition-overriding=true
问题2.java.lang.NoClassDefFoundError: io/netty/bootstrap/ServerBootstrap
问题2报io/netty/bootstrap/ServerBootstrap这个类找不到,既然找不到类,那么我们就需要导入这个类对应的jar包依赖:
<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</dependency>
dubbo框架是属于RPC远程过程调用的一种,而PRC协议的通信又是依赖于netty框架,而netty又是基于Java的NIO实现的,所以我们需要导入io/netty包
问题3.java.lang.ClassNotFoundException: org.apache.curator.framework.CuratorFrameworkFactory
和问题2一样报类找不到,需要导入对应的pom依赖
<!-- https://mvnrepository.com/artifact/org.apache.curator/curator-recipes -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.13.0</version>
</dependency>
我们本次集成dubbo使用的是官方推荐的zookeeper注册中心,而curator是Netflix公司开源的一套zookeeper客户端框架,解决了很多Zookeeper客户端非常底层的细节开发工作,包括连接重连、反复注册Watcher和NodeExistsException异常等等,所以我们需要导入org.apache.curator包
至此,duboo的坑便踩完了,重新启动服务,发现我们的服务正式启动成功并在zookeeper注册中心完成注册: