- 1. 基于分布式的微服务架构
- 2. SpringBoot 和 SpringCloud 版本
- 3. 由SpringCloud官方参考文档 来决定使用哪个版本的SpringBoot
- 3. SpringCloud 维护升级以及每个服务对应的技术架构
- 4. 微服务cloud整体 聚合父工程Project
- 5.微服务cloud整体 父工程pom.xml文件配置
- 6. SpringBoot 整合mybatis
- 7. 热部署 Devtools
- 8. Dashboard的使用
- 9. 公用模块-common
- 10. Hutool包的使用
- 11. Maven项目 如何转成SpringBoot项目
介绍SpringCloud,以及搭建环境。
1. 基于分布式的微服务架构SpringCloud是分布式微服务架构的一站式解决方案,是多种微服务架构落地技术的集合体。俗称:微服务全家桶。
整体架构图:
之前SpringCloud有D版和SpringBoot 1.X版配合搭建,这两个版本已经过时了。
现在使用SpringCloud H版和SpringBoot 2.X版。
SpringCloud的版本命名规则:
SpringBoot和SpringCloud有严格的版本对应,他们之前不同版本可能存在冲突!因此必须严格按照官网来对应。
更详细的版本对应查看网址:http://start.spring.io/actuator/info
之后使用,JSON处理工具:tool.lu 格式化出来:
之后学习的环境搭建版本:
以下红叉的是已经停止更新维护的。
服务注册中心:
服务调用:
服务降级(熔断):
服务网关:
服务配置:
服务总线:
总体上,技术图:
4. 微服务cloud整体 聚合父工程Project因为使用的是maven环境,就是约定 > 配置 > 编码。
第一步:创建maven父工程项目,选择maven版本。
第二步:修改整个项目环境的字符编码集,改为UTF-8。
Transparent native-to-ascii conversion的意思是:自动转换ASCII编码。
第三步:注解生效激活。
- 启动注解处理:
第四步:java编辑版本选择8版本。
第五步:File Type 过滤,随意设置,这个就是过滤那些像.idea ,.iml等等的这种和代码本身没有直接关联的可以不让他们显示。
第一步:packaging设置为pom,父工程都会设置为pom。
第二步:除了pom,像src文件夹都删除掉。
第三步:配置pom文件相关依赖版本。
4.0.0 com.itholmes.springcloud cloud2020 1.0-SNAPSHOT pom UTF-8 1.8 1.8 4.12 1.2.17 1.16.18 8.0.18 1.1.16 1.3.0 org.springframework.boot spring-boot-dependencies 2.2.2.RELEASE pom import org.springframework.cloud spring-cloud-dependencies Hoxton.SR1 pom import com.alibaba.cloud spring-cloud-alibaba-dependencies 2.1.0.RELEASE pom import org.mybatis.spring.boot mybatis-spring-boot-starter ${mybatis.spring.boot.version} junit junit ${junit.version} log4j log4j ${log4j.version} Maven http://maven.apache.org/ 2001
可以跳过单元测试的按钮:
type-aliases-package可以生命别名!!
mybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: com.itholmes.springcloud.entities # 所有Entity别名类所在包
useGeneratedKeys=“true” 和 keyProperty主键 从而返回值就是主键ID值:
- keyProperty中对应的值是实体类的属性,而不是数据库的字段。
7. 热部署 Devtoolsinsert into payment (serial) values (#{serial})
第一步:Adding devtools 。
org.springframework.boot spring-boot-devtools 2.7.0
第二步:Adding plugin。
org.springframework.boot spring-boot-maven-plugin true true
第三步:Enabling automatic build。设置idea。
第四步:update the value of。
在pom.xml文件执行快捷键:
第五步:重启idea,这样就会热部署自动化配置了。
8. Dashboard的使用启动多个项目的时候,就使用idea的Dashboard。
如何让Run Dashboard显示到idea的下方任务栏中:
第一步:打开父项目对应的.idea目录,找到workspace.xml文件。
第二步:添加配置如下中:
第三步:重启idea就可以了。
一般多个微服务都会公用一个公用模块项目(一般叫做common)。
这个项目存放的一般都是pojo类,Utils工具类等等公共代码。通过maven的install或者deploy的特性,通过GAV添加对应依赖,从本地或者私服来获得该jar包。
10. Hutool包的使用Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率。
Hutool是项目中“util”包友好的替代,它节省了开发人员对项目中公用类和公用工具方法的封装时间,使开发专注于业务,同时可以最大限度的避免封装不完善带来的bug。
11. Maven项目 如何转成SpringBoot项目cn.hutool hutool-all 5.6.5
第一步:导入SpringBoot相关依赖。
org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-devtools runtime true org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test org.mybatis.spring.boot mybatis-spring-boot-starter
第二步:在Resource目录下,创建application.yml文件。
第三步:在创建对应的SpringBoot启动Main方法。
package com.itholmes.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class OrderMain80 {
public static void main(String[] args) {
SpringApplication.run(OrderMain80.class,args);
}
}



