Springboot 整合Dubbo + zookeeper实现远程调用
由于网上搜到的很多都没法使用,自己研究了一下配置。
我这里zookeeper 安装在了docker上,最新版本应该是3.7.0,要注意pom文件中的zookeeper版本要一致。
然后是pom配置
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
<version>5.2.0</version>
</dependency>
yml的配置
server:
port: 8090
dubbo:
application:
name: dubbo-server
registry:
address: zookeeper://101.35.239.84:2181
timeout: 23000
protocol:
port: 20881
name: dubbo
启动类上添加注解**@EnableDubbo**
实现类Impl上添加**@DubboService**(替代了老版的Service)
@DubboService(interfaceClass = UserService.class)
public class UserServiceImpl implements UserService {
}
消费者调用接口则使用**@DubboReference**
@DubboReference(interfaceClass = UserService.class)
private UserService userService;
先起服务,再起消费。然后就应该可以正常使用啦
|