本文介绍了springboot整合dubbo教程之项目创建和环境搭建,分享给大家,具体如下:
1. 使用idea新建一个maven项目
新建项目
选择maven后,点击next下一步
选择项目类型
配置项目的maven坐标
设置项目名称和保存位置
修改项目的pom.xml文件
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<?xml version= "1.0" encoding= "utf-8" ?> <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.boot</groupid> <artifactid>boot-dubbo</artifactid> <version> 1.0 -snapshot</version> <!--在这里设置打包类型为pom,作用是为了实现多模块项目--> <packaging>pom</packaging> </project> |
2. 创建boot-dubbo的子模块项目
创建dubbo服务接口项目,我们把项目建立在刚才我们创建的boot-dubbo项目下面,作为boot-dubbo的子模块项目进行管理。
点击我们刚才新建好的项目,新建一个boot-dubbo的子模块 项目
新建项目的子模块项目
选择maven后点击 next
配置模块参数
完成项目子模块的创建
同理我们继续我们第二步的步骤,再次创建一个boot-dubbo-provider和boot-dubbo-consumer这两个子模块项目。
创建完成后,我们的整体项目结构图如下图所示:
项目完成结构图
至此,我们创建项目的准备工作已经完毕。
3. 定义每个项目的pom.xml文件
打开我们的顶层项目boot-dubbo的pom.xml文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
<?xml version= "1.0" encoding= "utf-8" ?> <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.boot</groupid> <artifactid>boot-dubbo</artifactid> <version> 1.0 -snapshot</version> <!-- 这里是我们子模块的设置 --> <modules> <module>boot-dubbo-api</module> <module>boot-dubbo-provider</module> <module>boot-dubbo-consumer</module> </modules> <!-- 在这里设置打包类型为pom,作用是为了实现多模块项目 --> <packaging>pom</packaging> <!-- 第一步:添加springboot的parent --> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version> 1.5 . 7 .release</version> </parent> <!-- 设置我们项目的一些版本属性 --> <properties> <project.build.sourceencoding>utf- 8 </project.build.sourceencoding> <java.version> 1.8 </java.version> <dubbo.version> 2.5 . 5 </dubbo.version> <zkclient.version> 0.10 </zkclient.version> <lombok.version> 1.16 . 18 </lombok.version> <spring-boot.version> 1.5 . 7 .release</spring-boot.version> </properties> <!-- 声明一些项目依赖管理,方便我们的依赖版本管理 --> <dependencymanagement> <dependencies> <!-- springboot依赖 --> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter</artifactid> <version>${spring-boot.version}</version> </dependency> <!-- springboot-web依赖 --> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> <version>${spring-boot.version}</version> </dependency> <!-- 使用lombok实现javabean的get、set、tostring、hashcode、equals等方法的自动生成 --> <dependency> <groupid>org.projectlombok</groupid> <artifactid>lombok</artifactid> <version>${lombok.version}</version> <scope>provided</scope> </dependency> <!-- dubbo依赖 --> <dependency> <groupid>com.alibaba</groupid> <artifactid>dubbo</artifactid> <version>${dubbo.version}</version> </dependency> <!-- zookeeper的客户端依赖 --> <dependency> <groupid>com.101tec</groupid> <artifactid>zkclient</artifactid> <version>${zkclient.version}</version> </dependency> </dependencies> </dependencymanagement> </project> |
boot-dubbo-api的pom.xml文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<?xml version= "1.0" encoding= "utf-8" ?> <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" > <parent> <artifactid>boot-dubbo</artifactid> <groupid>com.boot</groupid> <version> 1.0 -snapshot</version> </parent> <modelversion> 4.0 . 0 </modelversion> <artifactid>boot-dubbo-api</artifactid> <dependencies> <dependency> <groupid>org.projectlombok</groupid> <artifactid>lombok</artifactid> <scope>provided</scope> </dependency> </dependencies> </project> |
boot-dubbo-provider的pom.xml文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
<?xml version= "1.0" encoding= "utf-8" ?> <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" > <parent> <artifactid>boot-dubbo</artifactid> <groupid>com.boot</groupid> <version> 1.0 -snapshot</version> </parent> <modelversion> 4.0 . 0 </modelversion> <artifactid>boot-dubbo-provider</artifactid> <dependencies> <dependency> <groupid>com.boot</groupid> <artifactid>boot-dubbo-api</artifactid> <version> 1.0 -snapshot</version> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter</artifactid> </dependency> <dependency> <groupid>com.alibaba</groupid> <artifactid>dubbo</artifactid> </dependency> <dependency> <groupid>com.101tec</groupid> <artifactid>zkclient</artifactid> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build> </project> |
boot-dubbo-consumer的pom.xml文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
<?xml version= "1.0" encoding= "utf-8" ?> <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" > <parent> <artifactid>boot-dubbo</artifactid> <groupid>com.boot</groupid> <version> 1.0 -snapshot</version> </parent> <modelversion> 4.0 . 0 </modelversion> <artifactid>boot-dubbo-consumer</artifactid> <dependencies> <dependency> <groupid>com.boot</groupid> <artifactid>boot-dubbo-api</artifactid> <version> 1.0 -snapshot</version> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid>com.alibaba</groupid> <artifactid>dubbo</artifactid> </dependency> <dependency> <groupid>com.101tec</groupid> <artifactid>zkclient</artifactid> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build> </project> |
项目地址:springboot-dubbo项目github地址 https://github.com/zhangxieliu/springboot-dubbo
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://www.jianshu.com/p/6361a670ebf7