SpringBoot整合Dubbo
基础环境准备:
1.安装zookeeper(注意在配置文件中修改管理端口8080,防止端口占用报错)
示例:在zoo.cfg加入配置 admin.serverPort=[自定义端口]
2.Springboot项目添加依赖
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.7.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.5.3-beta</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
Dubbo的springboot配置文件:
1.服务提供者配置
spring.application.name=provider
server.port=8081
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880
#扫描接口实现package
dubbo.scan.base-packages=com.jack.provider.impl
2.服务消费者配置
spring.application.name=consumer
server.port=8082
dubbo.registry.address=zookeeper://127.0.0.1:2181
编码:(注解一定要用dubbo包的)
1.编写共用接口模块
2.服务提供模块在接口实现类加@Service注解
3.服务消费模块使用@Reference注入