一、SpringCloud 学习环境搭建
1.1、介绍
- 我们会使用一个Dept部门模块做一个微服务通用案例Consumer消费者(Client)通过REST调用Provider提供者(Server)提供的服务。
- 回顾Spring,SpringMVC,Mybatis等以往学习的知识。
- Maven的分包分模块架构复习。
一个简单的Maven项目结构是这样的:
-- app-parent: 一个父项目(app-parent)聚合了很多子项目(app-util\app-dao\app-web...) |-- pom.xml | |-- app-core ||---- pom.xml | |-- app-web ||---- pom.xml ......
一个父工程带着多个Moudule子模块
MicroServiceCloud父工程(Project)下初次带着3个子模块(Module)
- microservicecloud-api 【封装的整体entity/接口/公共配置等】
- microservicecloud-consumer-dept-80 【服务提供者】
- microservicecloud-provider-dept-8001 【服务消费者】
1.2、pringCloud版本选择
大版本说明:
SpringBoot | SpringCloud | 关系 |
---|---|---|
1.2.x | Angel版本(天使) | 兼容SpringBoot1.2x |
1.3.x | Brixton版本(布里克斯顿) | 兼容SpringBoot1.3x,也兼容SpringBoot1.4x |
1.4.x | Camden版本(卡姆登) | 兼容SpringBoot1.4x,也兼容SpringBoot1.5x |
1.5.x | Dalston版本(多尔斯顿) | 兼容SpringBoot1.5x,不兼容SpringBoot2.0x |
1.5.x | Edgware版本(埃奇韦尔) | 兼容SpringBoot1.5x,不兼容SpringBoot2.0x |
2.0.x | Finchley版本(芬奇利) | 兼容SpringBoot2.0x,不兼容SpringBoot1.5x |
2.1.x | Greenwich版本(格林威治) |
实际开发版本关系:使用后两个
spring-boot-starter-parent | spring-cloud-dependencles | ||
---|---|---|---|
版本号 | 发布日期 | 版本号 | 发布日期 |
1.5.2.RELEASE | 2017-03 | Dalston.RC1 | 2017-x |
1.5.9.RELEASE | 2017-11 | Edgware.RELEASE | 2017-11 |
1.5.16.RELEASE | 2018-04 | Edgware.SR5 | 2018-10 |
1.5.20.RELEASE | 2018-09 | Edgware.SR5 | 2018-10 |
2.0.2.RELEASE | 2018-05 | Fomchiey.BULD-SNAPSHOT | 2018-x |
2.0.6.RELEASE | 2018-10 | Fomchiey-SR2 | 2018-10 |
2.1.4.RELEASE | 2019-04 | Greenwich.SR1 | 2019-03 |
1.3、创建父工程(新的空的maven项目)
- 新建父工程项目springcloud,切记Packageing是pom模式
- 主要是定义POM文件,将后续各个子模块公用的jar包等统一提取出来,类似一个抽象父类
父工程pom依赖:
1 <!--打包方式 pom--> 2 <packaging>pom</packaging> 3 <properties> 4 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 5 <!--maven编译器版本--> 6 <maven.compiler.source>1.8</maven.compiler.source> 7 <maven.compiler.target>1.8</maven.compiler.target> 8 <!--在父项目中管理版本--> 9 <junit.version>4.12</junit.version> 10 <log4j.version>1.2.17</log4j.version> 11 <lombok.version>1.16.18</lombok.version> 12 </properties> 13 <!--表示依赖管理,在子项目中要使用对应的jar包,直接引用父类中的--> 14 <dependencyManagement> 15 <dependencies> 16 <dependency> 17 <groupId>org.springframework.cloud</groupId> 18 <artifactId>spring-cloud-alibaba-dependencies</artifactId> 19 <version>0.2.0.RELEASE</version> 20 <type>pom</type> 21 <scope>import</scope> 22 </dependency> 23 <!--springCloud的依赖--> 24 <dependency> 25 <groupId>org.springframework.cloud</groupId> 26 <artifactId>spring-cloud-dependencies</artifactId> 27 <version>Greenwich.SR1</version> 28 <type>pom</type> 29 <scope>import</scope> 30 </dependency> 31 <!--SpringBoot--> 32 <dependency> 33 <groupId>org.springframework.boot</groupId> 34 <artifactId>spring-boot-dependencies</artifactId> 35 <version>2.1.4.RELEASE</version> 36 <type>pom</type> 37 <scope>import</scope> 38 </dependency> 39 <!--数据库--> 40 <dependency> 41 <groupId>mysql</groupId> 42 <artifactId>mysql-connector-java</artifactId> 43 <version>5.1.47</version> 44 </dependency> 45 <dependency> 46 <groupId>com.alibaba</groupId> 47 <artifactId>druid</artifactId> 48 <version>1.1.10</version> 49 </dependency> 50 <!--SpringBoot 启动器--> 51 <dependency> 52 <groupId>org.mybatis.spring.boot</groupId> 53 <artifactId>mybatis-spring-boot-starter</artifactId> 54 <version>1.3.2</version> 55 </dependency> 56 <!--日志测试~--> 57 <dependency> 58 <groupId>ch.qos.logback</groupId> 59 <artifactId>logback-core</artifactId> 60 <version>1.2.3</version> 61 </dependency> 62 <dependency> 63 <groupId>junit</groupId> 64 <artifactId>junit</artifactId> 65 <version>${junit.version}</version> 66 </dependency> 67 <dependency> 68 <groupId>log4j</groupId> 69 <artifactId>log4j</artifactId> 70 <version>${log4j.version}</version> 71 </dependency> 72 <dependency> 73 <groupId>org.projectlombok</groupId> 74 <artifactId>lombok</artifactId> 75 <version>${lombok.version}</version> 76 </dependency> 77 </dependencies> 78 </dependencyManagement>
原文地址:https://www.cnblogs.com/zhangzhixi/p/14370095.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。