前面的項目,咱們會發現有個接口是同樣的,咱們須要單獨抽取出來,統一維護;apache
以及兩個項目的maven依賴包的版本也是同樣的,咱們也須要單獨抽取出來,統一維護;json
抽取接口,咱們經過新建一個項目,而後其餘兩個項目依賴這個這個項目便可;api
統一依賴包版本,咱們能夠經過創建parent項目,來統一管理依賴以及版本,子項目繼承便可;maven
咱們新建dubbo-demo-api項目,而後把DemoProviderService接口類放到該項目裏便可;ide
咱們再新建一個dubbo-demo-parent項目;測試
pom.xml裏:spa
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 2 <modelVersion>4.0.0</modelVersion> 3 <groupId>com.wishwzp</groupId> 4 <artifactId>dubbo-demo-parent</artifactId> 5 <version>0.0.1-SNAPSHOT</version> 6 <packaging>pom</packaging> 7 8 <!-- 依賴版本管理 --> 9 <properties> 10 <dubbo-demo-api.version>0.0.1-SNAPSHOT</dubbo-demo-api.version> 11 <dubbo.version>2.6.0</dubbo.version> 12 <zkclient.version>0.10</zkclient.version> 13 <curator-framework.version>4.0.1</curator-framework.version> 14 <fastjson.version>1.2.46</fastjson.version> 15 <log4j.version>1.2.17</log4j.version> 16 <slf4j-api.version>1.7.25</slf4j-api.version> 17 <commons-lang3.version>3.4</commons-lang3.version> 18 <netty-all.version>4.0.35.Final</netty-all.version> 19 </properties> 20 21 <!-- 依賴管理--> 22 <dependencyManagement> 23 <dependencies> 24 <dependency> 25 <groupId>com.wishwzp</groupId> 26 <artifactId>dubbo-demo-api</artifactId> 27 <version>${dubbo-demo-api.version}</version> 28 </dependency> 29 <dependency> 30 <groupId>com.alibaba</groupId> 31 <artifactId>dubbo</artifactId> 32 <version>${dubbo.version}</version> 33 </dependency> 34 <dependency> 35 <groupId>com.101tec</groupId> 36 <artifactId>zkclient</artifactId> 37 <version>${zkclient.version}</version> 38 </dependency> 39 <dependency> 40 <groupId>org.apache.curator</groupId> 41 <artifactId>curator-framework</artifactId> 42 <version>${curator-framework.version}</version> 43 </dependency> 44 <dependency> 45 <groupId>com.alibaba</groupId> 46 <artifactId>fastjson</artifactId> 47 <version>${fastjson.version}</version> 48 </dependency> 49 <dependency> 50 <groupId>log4j</groupId> 51 <artifactId>log4j</artifactId> 52 <version>${log4j.version}</version> 53 </dependency> 54 <dependency> 55 <groupId>org.slf4j</groupId> 56 <artifactId>slf4j-api</artifactId> 57 <version>${slf4j-api.version}</version> 58 </dependency> 59 <dependency> 60 <groupId>org.apache.commons</groupId> 61 <artifactId>commons-lang3</artifactId> 62 <version>${commons-lang3.version}</version> 63 </dependency> 64 <dependency> 65 <groupId>io.netty</groupId> 66 <artifactId>netty-all</artifactId> 67 <version>${netty-all.version}</version> 68 </dependency> 69 </dependencies> 70 </dependencyManagement> 71 </project>
dubbo-demo-provider項目pom.xml修改:.net
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 2 <modelVersion>4.0.0</modelVersion> 3 <parent> 4 <groupId>com.wishwzp</groupId> 5 <artifactId>dubbo-demo-parent</artifactId> 6 <version>0.0.1-SNAPSHOT</version> 7 </parent> 8 <artifactId>dubbo-demo-provider</artifactId> 9 10 <dependencies> 11 <dependency> 12 <groupId>com.wishwzp</groupId> 13 <artifactId>dubbo-demo-api</artifactId> 14 </dependency> 15 <dependency> 16 <groupId>com.alibaba</groupId> 17 <artifactId>dubbo</artifactId> 18 </dependency> 19 <dependency> 20 <groupId>com.101tec</groupId> 21 <artifactId>zkclient</artifactId> 22 </dependency> 23 <dependency> 24 <groupId>org.apache.curator</groupId> 25 <artifactId>curator-framework</artifactId> 26 </dependency> 27 <dependency> 28 <groupId>com.alibaba</groupId> 29 <artifactId>fastjson</artifactId> 30 </dependency> 31 <dependency> 32 <groupId>log4j</groupId> 33 <artifactId>log4j</artifactId> 34 </dependency> 35 <dependency> 36 <groupId>org.slf4j</groupId> 37 <artifactId>slf4j-api</artifactId> 38 </dependency> 39 <dependency> 40 <groupId>org.apache.commons</groupId> 41 <artifactId>commons-lang3</artifactId> 42 </dependency> 43 <dependency> 44 <groupId>io.netty</groupId> 45 <artifactId>netty-all</artifactId> 46 </dependency> 47 </dependencies> 48 </project>
相似,dubbo-demo-consumer項目pom.xml修改:netty
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 2 <modelVersion>4.0.0</modelVersion> 3 <parent> 4 <groupId>com.wishwzp</groupId> 5 <artifactId>dubbo-demo-parent</artifactId> 6 <version>0.0.1-SNAPSHOT</version> 7 </parent> 8 <artifactId>dubbo-demo-consumer</artifactId> 9 10 <dependencies> 11 <dependency> 12 <groupId>com.wishwzp</groupId> 13 <artifactId>dubbo-demo-api</artifactId> 14 </dependency> 15 <dependency> 16 <groupId>com.alibaba</groupId> 17 <artifactId>dubbo</artifactId> 18 </dependency> 19 <dependency> 20 <groupId>com.101tec</groupId> 21 <artifactId>zkclient</artifactId> 22 </dependency> 23 <dependency> 24 <groupId>org.apache.curator</groupId> 25 <artifactId>curator-framework</artifactId> 26 </dependency> 27 <dependency> 28 <groupId>com.alibaba</groupId> 29 <artifactId>fastjson</artifactId> 30 </dependency> 31 <dependency> 32 <groupId>log4j</groupId> 33 <artifactId>log4j</artifactId> 34 </dependency> 35 <dependency> 36 <groupId>org.slf4j</groupId> 37 <artifactId>slf4j-api</artifactId> 38 </dependency> 39 <dependency> 40 <groupId>org.apache.commons</groupId> 41 <artifactId>commons-lang3</artifactId> 42 </dependency> 43 <dependency> 44 <groupId>io.netty</groupId> 45 <artifactId>netty-all</artifactId> 46 </dependency> 47 </dependencies> 48 </project>
測試結果OK;code