# Spring与SpringBoot

## Spring能做什么

### Spring的能力

![](https://937995404-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MMTM8NYe0uekudlCMKb%2F-MP9X0OjIaz-2SEpUEWD%2F-MP9XLWb6vtlRFFRyk0R%2Fimage.png?alt=media\&token=9f95bad5-c526-474d-8fae-7d88ec40e373)

### Spring的生态

SpringBoot官网：<https://spring.io/projects/spring-boot>

* web开发
* 数据访问
* 安全控制
* 分布式
* 消息服务
* 移动开发
* 批处理
* ......

## Spring5重大升级

### 响应式编程

![](https://937995404-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MMTM8NYe0uekudlCMKb%2F-MP9X0OjIaz-2SEpUEWD%2F-MP9Y98fNPX5qudh5aCs%2Fimage.png?alt=media\&token=055a729a-a02a-49b2-b4b3-5c890be1ebf2)

### 内部源码设计

基于Java8的一些新特性，如：接口默认实现。重新设计源码架构。

## SpringBoot优点

* Create stand-alone Spring applications
* * 创建独立Spring应用
* Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
* * 内嵌web服务器
* Provide opinionated 'starter' dependencies to simplify your build configuration
* * 自动starter依赖，简化构建配置
* Automatically configure Spring and 3rd party libraries whenever possible
* * 自动配置Spring以及第三方功能
* Provide production-ready features such as metrics, health checks, and externalized configuration
* * 提供生产级别的监控、健康检查及外部化配置
* Absolutely no code generation and no requirement for XML configuration
* * 无代码生成、无需编写XML

> SpringBoot是整合Spring技术栈的一站式框架
>
> SpringBoot是简化Spring技术栈的快速开发脚手架

## 时代背景

### 微服务

[James Lewis and Martin Fowler (2014)](https://martinfowler.com/articles/microservices.html)  提出微服务完整概念。<https://martinfowler.com/microservices/>

> In short, the **microservice architectural style** is an approach to developing a single application as a **suite of small services**, each **running in its own process** and communicating with **lightweight** mechanisms, often an **HTTP** resource API. These services are **built around business capabilities** and **independently deployable** by fully **automated deployment** machinery. There is a **bare minimum of centralized management** of these services, which may be **written in different programming languages** and use different data storage technologies.-- [James Lewis and Martin Fowler (2014)](https://martinfowler.com/articles/microservices.html)

* 微服务是一种架构风格<br>
* 一个应用拆分为一组小型服务<br>
* 每个服务运行在自己的进程内，也就是可独立部署和升级<br>
* 服务之间使用轻量级HTTP交互<br>
* 服务围绕业务功能拆分<br>
* 可以由全自动部署机制独立部署<br>
* 去中心化，服务自治。服务可以使用不同的语言、不同的存储技术

### 分布式

![](https://937995404-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MMTM8NYe0uekudlCMKb%2F-MP9X0OjIaz-2SEpUEWD%2F-MP9YbX-xVKBQbLJwRHJ%2Fimage.png?alt=media\&token=78911e3b-8936-4351-b5a9-dfebad675245)

#### 分布式的困难

* 远程调用
* 服务发现
* 负载均衡
* 服务容错
* 配置管理
* 服务监控
* 链路追踪
* 日志管理
* 任务调度
* ......

#### 分布式的解决 <a href="#id-45zs4" id="id-45zs4"></a>

* SpringBoot + SpringCloud

![](https://937995404-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MMTM8NYe0uekudlCMKb%2F-MP9X0OjIaz-2SEpUEWD%2F-MP9YjlgTvD0lYc351Ga%2Fimage.png?alt=media\&token=2e175203-fa6d-473c-9cbc-916bf9e29056)

## 云原生

原生应用如何上云。 Cloud Native

### 上云的困难

* 服务自愈
* 弹性伸缩
* 服务隔离
* 自动化部署
* 灰度发布
* 流量治理
* ......

### 上云的解决

![](https://937995404-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MMTM8NYe0uekudlCMKb%2F-MP9X0OjIaz-2SEpUEWD%2F-MP9Z1SJCufvMn1dpdv4%2Fimage.png?alt=media\&token=702563f0-5530-41a5-9d00-454865e59200)

## 学习SpringBoot

文档地址：<https://docs.spring.io/spring-boot/docs/current/reference/html/>

![](https://937995404-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MMTM8NYe0uekudlCMKb%2F-MP9X0OjIaz-2SEpUEWD%2F-MP9ZLxal-jaCrcubg6V%2Fimage.png?alt=media\&token=16b95a2e-d4e1-41ae-a986-91209e8c9b9b)

查看新版特性：<https://github.com/spring-projects/spring-boot/wiki#release-notes>
