java1234开源博客系统
博客信息

接口抽取及依赖版本统一

发布时间:『 2018-02-28 23:11』  博客类别:Dubbo  阅读(5020) 评论(0)

前面的项目,我们会发现有个接口是一样的,我们需要单独抽取出来,统一维护;

以及两个项目的maven依赖包的版本也是一样的,我们也需要单独抽取出来,统一维护;


抽取接口,我们通过新建一个项目,然后其他两个项目依赖这个这个项目即可;

统一依赖包版本,我们可以通过建立parent项目,来统一管理依赖以及版本,子项目继承即可;


我们新建dubbo-demo-api项目,然后把DemoProviderService接口类放到该项目里即可;


我们再新建一个dubbo-demo-parent项目;


pom.xml里:

<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">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.java1234</groupId>
  <artifactId>dubbo-demo-parent</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  
  <!-- 依赖版本管理 -->
  <properties>
  	 <dubbo-demo-api.version>0.0.1-SNAPSHOT</dubbo-demo-api.version>
  	 <dubbo.version>2.6.0</dubbo.version>
  	 <zkclient.version>0.10</zkclient.version>
  	 <curator-framework.version>4.0.1</curator-framework.version>
  	 <fastjson.version>1.2.46</fastjson.version>
  	 <log4j.version>1.2.17</log4j.version>
  	 <slf4j-api.version>1.7.25</slf4j-api.version>
  	 <commons-lang3.version>3.4</commons-lang3.version>
  	 <netty-all.version>4.0.35.Final</netty-all.version>
  </properties>
   
   <!-- 依赖管理-->
   <dependencyManagement>
   	<dependencies>
	   	<dependency>
		    	<groupId>com.java1234</groupId>
				<artifactId>dubbo-demo-api</artifactId>
				<version>${dubbo-demo-api.version}</version>
	   		</dependency>
		    <dependency>
		        <groupId>com.alibaba</groupId>
		        <artifactId>dubbo</artifactId>
		        <version>${dubbo.version}</version>
		    </dependency>
		    <dependency>
		        <groupId>com.101tec</groupId>
		        <artifactId>zkclient</artifactId>
		        <version>${zkclient.version}</version>
		    </dependency>
		    <dependency>
		        <groupId>org.apache.curator</groupId>
		        <artifactId>curator-framework</artifactId>
		        <version>${curator-framework.version}</version>
		    </dependency>
		    <dependency>
		        <groupId>com.alibaba</groupId>
		        <artifactId>fastjson</artifactId>
		        <version>${fastjson.version}</version>
		    </dependency>
		    <dependency>
		        <groupId>log4j</groupId>
		        <artifactId>log4j</artifactId>
		        <version>${log4j.version}</version>
		    </dependency>
		    <dependency>
		        <groupId>org.slf4j</groupId>
		        <artifactId>slf4j-api</artifactId>
		        <version>${slf4j-api.version}</version>
		    </dependency>
		    <dependency>
		        <groupId>org.apache.commons</groupId>
		        <artifactId>commons-lang3</artifactId>
		        <version>${commons-lang3.version}</version>
		    </dependency>
		    <dependency>
		        <groupId>io.netty</groupId>
		        <artifactId>netty-all</artifactId>
		        <version>${netty-all.version}</version>
		    </dependency>
  	 </dependencies>
   </dependencyManagement>
</project>


dubbo-demo-provider项目pom.xml修改:

<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">
  <modelVersion>4.0.0</modelVersion>
  <parent>
      <groupId>com.java1234</groupId>
	  <artifactId>dubbo-demo-parent</artifactId>
	  <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>dubbo-demo-provider</artifactId>
  
  <dependencies>
        <dependency>
	    	<groupId>com.java1234</groupId>
			<artifactId>dubbo-demo-api</artifactId>
   		</dependency>
	    <dependency>
	        <groupId>com.alibaba</groupId>
	        <artifactId>dubbo</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>com.101tec</groupId>
	        <artifactId>zkclient</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>org.apache.curator</groupId>
	        <artifactId>curator-framework</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>com.alibaba</groupId>
	        <artifactId>fastjson</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>log4j</groupId>
	        <artifactId>log4j</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>org.slf4j</groupId>
	        <artifactId>slf4j-api</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>org.apache.commons</groupId>
	        <artifactId>commons-lang3</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>io.netty</groupId>
	        <artifactId>netty-all</artifactId>
	    </dependency>
	</dependencies>
</project>


类似,dubbo-demo-consumer项目pom.xml修改:

<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">
  <modelVersion>4.0.0</modelVersion>
  <parent>
      <groupId>com.java1234</groupId>
	  <artifactId>dubbo-demo-parent</artifactId>
	  <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>dubbo-demo-consumer</artifactId>
  
  <dependencies>
 		<dependency>
	    	<groupId>com.java1234</groupId>
			<artifactId>dubbo-demo-api</artifactId>
   		</dependency>
	    <dependency>
	        <groupId>com.alibaba</groupId>
	        <artifactId>dubbo</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>com.101tec</groupId>
	        <artifactId>zkclient</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>org.apache.curator</groupId>
	        <artifactId>curator-framework</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>com.alibaba</groupId>
	        <artifactId>fastjson</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>log4j</groupId>
	        <artifactId>log4j</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>org.slf4j</groupId>
	        <artifactId>slf4j-api</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>org.apache.commons</groupId>
	        <artifactId>commons-lang3</artifactId>
	    </dependency>
	    <dependency>
	        <groupId>io.netty</groupId>
	        <artifactId>netty-all</artifactId>
	    </dependency>
  </dependencies>
</project>



测试结果OK;


关键字:   Dubbo  
关注Java1234微信公众号
博主信息
Java1234_小锋
(知识改变命运,技术改变世界)
Powered by Java1234 V3.0 Copyright © 2012-2016 Java知识分享网 版权所有