人们把Spring Boot称为搭建程序的脚手架。它能帮我们快速的构建庞大的spring项目,并且尽可能的减少一切xml配置,这样我们在开发时关注点集中在了业务问题上,而不再是配置问题上,可以非常轻松的开始应用程序。
SpringBoot的核心功能
-
起步依赖: 起步依赖本质上是一个Maven项目对象模型(Project Object Model,POM),定义了对其他库的传递依赖,这些东西加在一起即支持某项功能。 简单的说,起步依赖就是将具备某种功能的坐标打包到一起,并提供一些默认的功能。
-
自动配置: Spring Boot的自动配置是一个运行时(更准确地说,是应用程序启动时)的过程,考虑了众多因素,才决定Spring配置应该用哪个,不该用哪个。该过程是Spring自动完成的。
[](
)SpringBoot 快速入门
项目结构:
1. 创建一个Maven工程,在pom.xml中导入Spring Boot相关的依赖:
创建工程:
首先File->new Project,选择Maven工程,这里不需要勾选Create from archetype,
点击next之后,配置自己的工程名称,点击finish
引入依赖:
找到项目目录中的pom.xml配置文件,所有的springboot的工程都以spring父工程为父工程,我们必须进行配置,父工程:spring-boot-starter-parent
,如果我们要进行web开发还要配置web功能的起步依赖spring-boot-starter-web
。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--配置父工程,导入下面的配置就表示这是一个springboot的项目-->
<!--这个父工程的目的就是依赖般的锁定-->
<!--所有的springboot的工程都以spring父工程为父工程,必须继承spring-boot-starter-parent -->
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.0.1.RELEASE</version>
</parent>
<groupId>org.example</groupId>
<artifactId>SpringBoot_quick</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!--web功能的起步依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!--@ConfiguaritionProperties的执行器配置:根据配置文件时,给出对应提示-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<opt