SpringBoot介绍
spring boot来简化spring应用开发,约定大于配置,去繁从简,just run就能创建一个独立的,产品 级别的应用
用来简化Spring应用的初始搭建及开发过程,使用特定的方式来配置(propert或ymal文件)。
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
- 提供生产级别的监控、健康检查及外部化配置(SpringBoot Actuator、Profile环境切换)
- Absolutely no code generation and no requirement for XML configuration
- 无代码生成、无需编写XML
- SpringBoot是整合Spring技术栈的一站式框架
- SpringBoot是简化Spring技术栈的快速开发脚手架
SpringBoot的运行方式
- 直接执行main() 方法。
- 打包用命令行或放到容器中运行。
例:java -jar demo.jar
- 通过Maven或Gradle插件运行。
如何理解 Spring Boot 中的 Starters?
Starters是什么: Starters可以理解为是启动器,它包含了一系列可以集成到应用的里面的依赖包。
你可以一站式集成Spring 及其他技术,而不需要到处找示例代码和依赖包。
如你想使用Spring JPA访问数据库,只要加入spring-boot-starter-data-jpa启动器依赖就能使用了。Starters包含了许多项目中需要用到的依赖,它们能快速持续的运行,都是一系列得到支持的管理传递性依赖。
开发导入starter场景启动器
- 见到很多 spring-boot-starter-* : *就某种场景
- 只要引入starter,这个场景的所有常规需要的依赖我们都自动引入
- 见到的 *-spring-boot-starter: 第三方为我们提供的简化开发的场景启动器。
Starters命名: Spring Boot官方的启动器都是以spring-boot-starter-命名的,代表了一个特定的应用类型。第三方的 启动器不能以spring-boot开头命名,它们都被Spring Boot官方保留。一般一个第三方的应该这样命 名,像mybatis的mybatis-spring-boot-starter。
所有SpringBoot场景启动器最底层的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${version}</version>
<scope>compile</scope>
</dependency>
<!-- spring-boot-dependencies包管理版本号 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<!-- 该依赖里面以及写号版本号 -->
<properties>
<activemq.version>5.16.5</activemq.version>
<antlr2.version>2.7.7</antlr2.version>
<appengine-sdk.version>1.9.98</appengine-sdk.version>
<artemis.version>2.19.1</artemis.version>
...
</properties>
- 无需关注版本号,自动版本仲裁 :spring-boot-dependencies
- 引入依赖默认都可以不写版本
- 引入非版本仲裁的jar,要写版本号。
<dependencyManagement>
<!-- 标签内的依赖子项目不继承,用于管理版本号 -->
</dependencyManagement>
<dependenies>
<!-- 标签内的依赖子项目 继承 -->
</dependenies>