Spring Boot 教程
欢迎阅读 Spring Boot 教程。Spring Boot是 Pivotal Team(Spring 团队)的一个全新项目。它是在现有 Spring 框架之上开发的框架。
Spring Boot 教程
Spring Boot 采用全新的开发模型,避免了一些繁琐的开发步骤和样板代码和配置,使 Java 开发变得非常容易。
什么是 Spring Boot?
Spring Boot 是“Spring 团队”推出的一个框架,旨在简化新 Spring 应用程序的引导和开发。它提供代码和注释配置的默认设置,以便快速启动新的 Spring 项目。它遵循“固定默认配置”方法,避免大量样板代码和配置,从而改进开发、单元测试和集成测试流程。
什么不是 Spring Boot?
Spring Boot Framework 不是由 Spring 团队从头实现的,而是在现有的 Spring Framework(Spring IO Platform)之上实现的。它不用于解决任何新问题。它用于解决与 Spring Framework 相同的问题。
为什么选择 Spring Boot?
- 简化基于Java的应用程序开发、单元测试和集成测试过程。
- 通过提供一些默认值来减少开发、单元测试和集成测试的时间。
- 提高生产力。
在这个阶段,不要担心什么是“固执己见的默认配置”方法。我们将在接下来的文章中通过一些示例详细解释这一点。
Spring Boot 的优点:
- 使用 Java 或 Groovy 开发基于 Spring 的应用程序非常容易。
- 它减少了大量开发时间并提高了生产力。
- 它避免编写大量样板代码、注释和 XML 配置。
- 将 Spring Boot 应用程序与其 Spring 生态系统(如 Spring JDBC、Spring ORM、Spring Data、Spring Security 等)集成非常容易。
- 它遵循“固定默认配置”方法,以减少开发人员的工作量
- 它提供嵌入式 HTTP 服务器(如 Tomcat、Jetty 等),以便非常轻松地开发和测试我们的 Web 应用程序。
- 它提供 CLI(命令行界面)工具,可以非常轻松、快速地从命令提示符开发和测试 Spring Boot(Java 或 Groovy)应用程序。
- 它提供了许多插件,可以使用 Maven 和 Gradle 等构建工具轻松开发和测试 Spring Boot 应用程序
- 它提供了许多插件,可以非常轻松地与嵌入式和内存数据库协同工作。
用简单的术语来说,Spring Boot 的含义是 Spring Boot 只不过是现有的 Spring 框架 + 一些嵌入式 HTTP 服务器(Tomcat/Jetty 等)- XML 或注释配置。这里的减号表示我们不需要编写任何 XML 配置,只需要编写一些注释。
Spring Boot 的主要目标:
The main goal of Spring Boot Framework is to reduce Development, Unit Test and Integration Test time and to ease the development of Production ready web applications very easily compared to existing Spring Framework, which really takes more time.
- To avoid XML Configuration completely
- To avoid defining more Annotation Configuration(It combined some existing Spring Framework Annotations to a simple and single Annotation)
- To avoid writing lots of import statements
- To provide some defaults to quick start new projects within no time.
- To provide Opinionated Development approach.
By providing or avoiding these things, Spring Boot Framework reduces Development time, Developer Effort and increases productivity.
Limitation/Drawback of Spring Boot:
Spring Boot Framework has one limitation. It is some what bit time consuming process to convert existing or legacy Spring Framework projects into Spring Boot Applications but we can convert all kinds of projects into Spring Boot Applications. It is very easy to create brand new/Greenfield Projects using Spring Boot. To Start Opinionated Approach to create Spring Boot Applications, The Spring Team (The Pivotal Team) has provided the following three approaches.
- Using Spring Boot CLI Tool
- Using Spring STS IDE
- Using Spring Initializr Website
We will discuss one by one in detail with some good examples in coming posts. We can find Spring Initializr Website at: https://start.spring.io/ We can develop two flavors of Spring-Based Applications using Spring Boot
- Java-Based Applications
- Groovy Applications
We can use Spring Boot CLI or Spring STS IDE or Spring Initializr Website to develop Spring Boot Groovy Applications. However, we can use Spring STS IDE or Spring Initializr Website to develop Spring Boot Java Applications. Anyhow, Groovy is also JVM language almost similar to Java Language. We can combine both Groovy and Java into one Project. Because like Java files, Groovy files are finally compiled into *.class files only. Both *.groovy and *.java files are converted to *.class file (Same byte code format). Spring Boot Framework Programming model is inspired by Groovy Programming model. Spring Boot internally uses some Groovy based techniques and tools to provide default imports and configuration. Spring Boot Framework also combined existing Spring Framework annotations into some simple or single annotations. We will explore those annotations one by one in coming posts with some real-time examples. Spring Boot Framework drastically changes Spring-Java Based Applications Programming model into new Programming model. As of now, Spring Boot is at initial stage only but future is all about Spring Boot only. Happy Spring Boot Framework Learning!