Git地址:https://github.com/boorZ/demo-dubbo.git
注意:Git地址上的项目与本文章有差同,请参照文章与Git。
Git地址:https://github.com/boorZ/demo-dubbo-xml
注意:Git地址上的项目与本文章有差同,请参照文章与Git。
项目结构(这是个父子项目)
还是解析下:
- demo-dubbo-xml是父项目
- dubbo-api是Service接口(如果您们要问:为什么我要把Service接口与Service实现类分开。对不起,个人喜好)
- dubbo-provider 是服务提供者
- dubbo-consumer 是服务消费者
父项目(demo-dubbo-xml)
pom.xml 添加如下依赖:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <!-- https://mvnrepository.com/artifact/com.alibaba.boot/dubbo-spring-boot-starter --> <dependency> <groupId>com.alibaba.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>0.2.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.curator/curator-framework --> <dependency> <groupId>org.apache.curator</groupId> <artifactId>curator-framework</artifactId> <version>4.2.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper --> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.5.5</version> <type>pom</type> </dependency> <!-- 出现service为null:根本原因是导包错误,导致dubbo和springboot没有集成成功--> <dependency> <groupId>io.dubbo.springboot</groupId> <artifactId>spring-boot-starter-dubbo</artifactId> <version>1.0.0</version> </dependency> |
dubbo-api所需更改:
DemoUser | |
DemoService | |
dubbo-provider所需更改:
pom.xml | |
DemoServiceImpl | |
application.properties | |
Application | 就是SpringBoot的启动类 添加注解让SpringBoot启动时读取Dubbo配置文件 |
dubbo-consumer所需更改:
pom.xml | |
DemoController | |
application.properties | |
Application | 就是SpringBoot的启动类 添加注解让SpringBoot启动时读取Dubbo配置文件 |