项目搭建
这里我搭建了三个项目,分别为dubbo-api,dubbo-consumer,dubbo-provider
dubbo-api:主要是接口定义,供dubbo-consumer调用,以及dubbo-provider的service层去实现该接口,分离这一层的好处就是前端项目调用接口时候,直接调用dubbo-api的接口即可,不需要关注后端如何实现;而service层来具体实现该接口,进行业务逻辑处理,不需要关注dubbo-consumer 的controller层如何调用。
dubbo-consumer:主要controller层控制跳转等。
dubbo-provider:主要是service实现,结合数据层实现后端业务逻辑处理。
项目搭建完成之后,的结构图如下:
三、项目配置
1、dubbo-api
Maven配置:
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.dubbo</groupId> <artifactId>dubbo-api</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>dubbo-api</name> <url>http://maven.apache.org</url> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.5</source> <target>1.5</target> <fork>true</fork> <meminitial>128m</meminitial> <maxmem>512m</maxmem> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <artifactId>maven-eclipse-plugin</artifactId> <version>2.5.1</version> <configuration> <additionalProjectnatures> <projectnature> org.springframework.ide.eclipse.core.springnature </projectnature> </additionalProjectnatures> <additionalBuildcommands> <buildcommand> org.springframework.ide.eclipse.core.springbuilder </buildcommand> </additionalBuildcommands> <downloadSources>false</downloadSources> <downloadJavadocs>false</downloadJavadocs> <wtpversion>1.5</wtpversion> </configuration> </plugin> <!-- 要加上下面的一句,否则执行:mvn package -Dmaven.test.skip=true的时候会报错 --> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> </plugin> </plugins> </build> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring.version>4.0.3.RELEASE</spring.version> <org.codehaus.jackson>1.9.13</org.codehaus.jackson> </properties> <dependencies> <!-- Test --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.7</version> <scope>test</scope> </dependency> </dependencies> </project> |
经典介绍: