1. SpringBoot简介:
1.1 Spring缺点:
1.2 SpringBoot的核心功能:
2. SpringBoot快速入门:
3. 原理分析:
3.1 起步依赖原理分析:
3.1.1 分析spring-boot-starter-parent
3.1.2 分析spring-boot-starter-web
3.2 自动配置原理解析:
1. SpringBoot简介:
全新框架(底层就是使用spring)简化Spring应用开发,约定大于配置。
1.1 Spring缺点:
尽管Spring组件代码是轻量级的,但它的配置却是重量级的
1.2 SpringBoot的核心功能:
起步依赖:
起步依赖本质上是一个Maven项目对象模型(Project Object Model,POM),定义了对其他库的传递依赖,这些东西加在一起即支持某项功能。简单的说,起步依赖就是将具备某种功能的坐标打包到一起,并提供一些默认的功能。
自动配置:
Spring Boot的自动配置是一个运行时(更准确地说,是应用程序启动时)的过程,考虑了众多因素,才决定Spring配置应该用哪个不该用哪个。该过程是Springg自动完成的。
2. SpringBoot快速入门:
1. 继承SpringBoot的起步依赖spring-boot-starter-parent
2. 项目要导入web的启动依赖
3. 编写SpringBoot引导类
4. 编写controller与成功访问 localhost:8080/路由
5. 热部署:spring-boot-devtools(idea也需要更改部分配置)



快速搭建:直接选择Spring Initializr,免去上面步骤

3. 原理分析:
3.1 起步依赖原理分析:
3.1.1 分析spring-boot-starter-parent

从上面的spring-boot-starter-dependencies的pom.xml中我们可以发现,一部分坐标的版本、依赖管理、插件管理已经定义好,所以我们的SpringBoot工程继承spring-boot-starter-parent后已经具备版本锁定等配置了。所以起步依赖的作用就是进行依赖的传递。
3.1.2 分析spring-boot-starter-web
点击spring-boot-starter-web,跳转到了spring-boot-starter-web的pom.xml,xml配置如下

spring-boot-starter-web就是将web开发要使用的spring-web、spring-webmvc等坐标进行了“打包”,这样我们的工程只要引入spring-boot-starter-web起步依赖的坐标就可以进行web开发了,同样体现了依赖传递的作用。
3.2 自动配置原理解析:



上面配置文件存在大量的以Confifiguration为结尾的类名称,这些类就是存有自动配置信息的类,而SpringApplication在获取这些类名后再加载

网友评论