SpringBoot深入分析学习

其实在17年入职目前公司的时候就已经接触了SpringBoot,当时公司重构代码,组长决定通过SpringBoot构建微服务架构,在会议室里面深入讲了一下微服务相关概念,当时也不是很懂,后来觉得SpringBoot就是为微服务所准备的,可以通过main函数运行。但其实SpringBoot版本发行是在2005年,而微服务这种概念的提出是在06年。本篇博客主要通过官网文档像大家介绍一下SpringBoot的基本概念。

基本概念

SpringBoot是Spring家族中的一份子。在官网中的概念如下所示:

1
2
3
4
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".

We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss.
Most Spring Boot applications need very little Spring configuration.

Spring Boot可以简单的创建单机的,生产级别的Spring应用使你可以直接运行。我们采取一个Spring平台固化视图和三方包,你可以更加轻量级的运行。大多数SpringBoot应用需要需要很少的Spring 配置。

通过上述概念可以说明的是Spring Boot创建的还是一个Spring的应用。并且Spring Boot更加轻量级,传统的Spring Boot de的配置很麻烦,要去关注各个三方应用的版本等问题。在Spring Boot中通过减少或者可以不用XML进行配置应用。通过自动装配等功能轻量级的开始一个应用。传统的Spring应用虽然功能很强大,但是并不是一个容器,它的生命周期还是通过Tomcat来完成的,而Spring Boot内嵌容器,使得生命周期可以自己去进行控制。

特性

官网中对Spring Boot的特性描述如下:

1
2
3
4
5
6
7
8
9
10
11
- Create stand-alone Spring applications

- Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)

- Provide opinionated 'starter' dependencies to simplify your build configuration

- Automatically configure Spring and 3rd party libraries whenever possible

- Provide production-ready features such as metrics, health checks and externalized configuration

- Absolutely no code generation and no requirement for XML configuration
  1. 创建单机的Spring应用。注意Spring Boot创建的还是Spring的应用。
  2. 内嵌Tomcat、Jetty可以直接运行,不需要去构建War包。内嵌容器可以更加方便构建Spring应用。并不是说内嵌容器的方式比通过打包使用脚本的方式效率或者速度更快。
  3. 提供’start’依赖去简化构建配置。
  4. 尽可能自动配置Spring和第三方库
  5. 提供生成级别的应用例如指标,运行状况检查和外部化配置
  6. 绝对没有代码生成也不需要XML配置。