简介
名称: 尚硅谷2020最新版SpringCloud(H版&alibaba)
时长: 26 H
集数: 150
作者: 周阳
21章 14种组件技术 10天的学习周期
-------基础P1~P14 (20201018—20201021)
-------初级P15~P46 (20201022—20201024 )
-------中级P
-------高级P
周阳套路
- 是什么
- 能干嘛
- 去哪下
- 怎么玩
基础
初级
中级
高级
笔记: Typora \ 印象笔记
思维导图: XMind \ MindMaster
微服务基础架构
SpringCloud组件及其替换组件
P05 – springCloud 父工程控件的创建
https://www.bilibili.com/video/BV18E411x7eT?p=5
8001 8002 服务提供者可以运行的条件是
- 本地Mysql开启,且密码没有问题(我公司与家里密码不一致)
- 本地Hosts文件修改,兼容集群访问(服务名就是本地主机127.0.0.1)
C:\Windows\System32\drivers\etc
P06父工程pom文件
https://www.bilibili.com/video/BV18E411x7eT?p=6
<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.atguigu.springcloud</groupId>
<artifactId>cloud2020</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<!--统一管理jar包版本-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compile.source>1.8</maven.compile.source>
<maven.compile.target>1.8</maven.compile.target>
<junit.version>4.12</junit.version>
<log4j.version>1.2.17</log4j.version>
<lombok.version>1.16.18</lombok.version>
<mysql.version>5.1.47</mysql.version>
<druid.version>1.1.16</druid.version>
<mybatis.spring.boot.version>1.3.0</mybatis.spring.boot.version>
</properties>
<!-- 子模块继承之后,提供作用:锁定版本+子module 不用写 groupId 和 version -->
<dependencyManagement>
<dependencies>
<!--spring boot 2.2.2-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- SpringCloud Hoxton.SR1 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--spring cloud alibaba 2.1.0.RELEASE-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis.spring.boot.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<optional>true</optional>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
P7 DependencyManagement vs Dependency
https://www.bilibili.com/video/BV18E411x7eT?p=7
Maven父类中的DependencyManagement 引入的依赖,并不实际调用下载
只有在子类的Dependencids中实际引入后,才执行实际的调用
P08 P09 P10 支付模块构建
https://www.bilibili.com/video/BV18E411x7eT?p=8
编码创建过程
- 建module
- 改pom
- 写YML
- 主启动
- 业务类
5.1 建表SQL
5.2 entities
-------------5.2.1 主实体 Payment
-------------5.2.2 json封装实体 CommonResult
5.3 dao
5.4 service
-------------5.4.1 service 接口
-------------5.4.2 service 接口实现类
5.5 controller
postman 测试 — 3 m
https://www.bilibili.com/video/BV18E411x7eT?p=10
8、测试
1、get测试:浏览器输入:http://localhost:8001/payment/get/2
结果:{“code”:200,“message”:“查询数据成功”,“data”:{“id”:2,“serial”:“alibaba”}}
run vs run dashboard
开启 Run DashBoard
默认开启两个module是打开 dashBoard 的
RunDashboard 节点下面增加 configurationType 节点如下
<component name="RunDashboard">
<option name="configurationTypes">
<set>
<option value="SpringBootApplicationConfigurationType" />
</set>
</option>
Devtools —热部署插件
https://www.bilibili.com/video/BV18E411x7eT?p=11
- add devtools to project (子工程)
- add plugin to pom (父工程)
- enabling automatic build
- Update the value of
- 重启IDEA
compiler.automake.allow.when.app.running
actionSystem.assertFocusAccessFromEdt
12 13 消费者订单模块
微服务提供者 端口号 8001
客户端消费者 端口号 80
httpClient 升级到 restTemplate
spring是容器处理集合
引入restTemplate需要使用config配置引入RestTemplate 的bean