1.什么是Spring
Spring框架为开发Java应用程序提供了全面的基础架构支持。
它包含了一些很好的功能,如依赖注入和开箱即用的模块:
- Spring JDBC
- Spring MVC
- Spring Security
- Spring AOP
- Spring ORM
- Spring Test
这些模块可以大大缩短应用程序开发的时间。
例如,在JavaWeb开发的早期阶段,我们需要编写大量的重复代码来将记录插入数据源中。但是通过使用Spring JDBC模块的JDBCTemplate,我们可以将它简化为只需几个简单配置或者几行代码。
2.Spring Boot
Spring Boot基本上是Spring框架的扩展,它消除了Spring应用程序所需的复杂的例行配置。
- 通过starter这一个依赖,以简化构建和复杂的应用程序配置
- 可以直接main函数启动,嵌入式web服务器,避免了应用程序部署的复杂性
- Metrics度量,Helth chech健康检查和外部化配置
- 自动化配置Spring功能
3.Maven依赖
Spring创建一个Web应用程序所需的最小依赖性:
<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.0.RELEASE</version>
</dependency>
</pre>
Spring Boot只需要一个依赖项来启动和运行Web应用程序
<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
</pre>
在构建期间,所有其他依赖项目管将自动添加到最终的归档中,
举例:我们通常使用Spring Test 、Junit、Hamcrest和Mockito库集。在Spring项目中我们需要将这些所有库添加为依赖项目。
但是在Spring Boot中,我们只需要用于测试的启动器依赖项来自动包含这些库。
Spring Boot为不同的Spring模块提供了许多入门依赖项:
- spring-boot-starter-data-jpa
- spring-boot-starter-security
- spring-boot-starter-test
- spring-boot-starte-thymeleaf
4.MVC配置
Spring Boot将自动扫描应用程序中存在的依赖项,属性和bean,并根据这些内容启用相应的配置。
5.打包和部署
Spring Boot内置了tomcat服务器。
所以在有JDK的环境下可以直接运行jar包。
也可以打包成war包在tomcat上运行。
https://www.jianshu.com/p/f8b0b8616d4f
总结:
1.Spring Boot是Spring本身的扩展,使开发,测试和部署更加方便。