简介
Spring Boot 是由 Pivotal 团队提供的全新框架。Spring Boot 是所有基于 Spring Framework 5.0 开发的项目的起点。Spring Boot 的设计是为了让你尽可能快的跑起来 Spring 应用程序并且尽可能减少你的配置文件。
优点
1.零配置,无冗余代码生成和XML 强制配置,遵循“约定大于配置,使得开发简单。
2.提供非功能性特征,如嵌入式服务器、安全性、度量、运行状况检查、外部化配置等
3.集成了大量常用的第三方库的配置,自动装配。
4.集成大量的测试框架,测试方便。
缺点
由于零配置封装了很多细节,所以增大了定位问题的难度。
快速入门
1.新建maven项目,项目结构如下

- 1、Application.java 建议放到根目录下面,主要用于做一些框架配置
- 2、controller 负责页面访问控制
2.pom文件中引入springboot
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
pom.xml 文件中默认有两个模块:
spring-boot-starter:核心模块,包括自动配置支持、日志和 YAML,spring-boot-starter-webweb 模块提供web应用必要的组件。spring-boot-starter-test:测试模块,包括 JUnit、Hamcrest、MockMvc。
3.编写controller
@RestController
public class HelloWorldController
{
@RequestMapping("/hello")
public String index()
{
return "Hello World";
}
}
@RestController 注解集成了@Controller和@ResponseBody两个注解,返回json数据结构,默认采用的是jackjson。
4. 启动主程序,浏览器中输入http://localhost:8080/hello,可以看到效果。
本文介绍了Spring Boot框架,它是基于Spring Framework 5.0开发项目的起点,能让Spring应用快速运行并减少配置。其优点包括零配置、提供非功能性特征、自动装配第三方库、方便测试;缺点是定位问题难度增大。还给出了Spring Boot快速入门的步骤。
1万+

被折叠的 条评论
为什么被折叠?



