SpringBoot简介

1.Spring Boot是什么,干嘛用的,有什么特征?

Spring Boot是Spring实现自动配置,降低项目搭建复杂度的一套完整的方案。Spring Boot本身并不提供Spring框架的核心特性以及扩展功能,只是用于快速、敏捷地开发新一代基于Spring框架的应用程序。也就是说,它并不是用来替代Spring的解决方案,而是和Spring框架紧密结合用于提升Spring开发者体验的工具。同时它集成了大量常用的第三方库配置(例如Jackson, JDBC, Mongo, Redis, Mail等等),Spring Boot应用中这些第三方库几乎可以零配置的开箱即用(out-of-the-box),大部分的Spring Boot应用都只需要非常少量的配置代码,开发者能够更加专注于业务逻辑。

 特点:

可以创建独立运行的Spring应用程序
内部集成Tomcat、Jetty或Undertow,无需部署war文件
提供基础依赖以简化配置
尽可能自动配置Spring和第三方依赖
提供生产-就绪功能,例如指标、运行健康状态监测、拓展配置
无代码生成,也无xml配置

2.Spring Boot 安装

2.1Java Developer的安装说明

2.1.1maven安装

通常,Maven POM文件继承自spring-boot-starter-parent项目并声明对一个或多个“Starter”的依赖关系。Spring Boot还提供了一个可选的 Maven插件来创建可执行jar。如下为一个典型POM文件:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 4     <modelVersion>4.0.0</modelVersion>
 5 
 6     <groupId>com.example</groupId>
 7     <artifactId>myproject</artifactId>
 8     <version>0.0.1-SNAPSHOT</version>
 9 
10     <!-- Inherit defaults from Spring Boot -->
11     <parent>
12         <groupId>org.springframework.boot</groupId>
13         <artifactId>spring-boot-starter-parent</artifactId>
14         <version>2.1.3.RELEASE</version>
15     </parent>
16 
17     <!-- Add typical dependencies for a web application -->
18     <dependencies>
19         <dependency>
20             <groupId>org.springframework.boot</groupId>
21             <artifactId>spring-boot-starter-web</artifactId>
22         </dependency>
23     </dependencies>
24 
25     <!-- Package as an executable jar -->
26     <build>
27         <plugins>
28             <plugin>
29                 <groupId>org.springframework.boot</groupId>
30                 <artifactId>spring-boot-maven-plugin</artifactId>
31             </plugin>
32         </plugins>
33     </build>
34 
35 </project>

如果有自己的父工程需要继承,可以通过使用scope=import实现对spring-boot-starter-parent工程的依赖来保持依赖管理的好处,如下所示:

 1 <dependencyManagement>
 2         <dependencies>
 3         <dependency>
 4             <!-- Import dependency management from Spring Boot -->
 5             <groupId>org.springframework.boot</groupId>
 6             <artifactId>spring-boot-dependencies</artifactId>
 7             <version>2.1.3.RELEASE</version>
 8             <type>pom</type>
 9             <scope>import</scope>
10         </dependency>
11     </dependencies>
12 </dependencyManagement>

前面示例不允许使用属性覆盖单个的依赖项,要想实现相同结果,可以在前面的依赖前添加对要覆盖的依赖项的新的依赖,如下所示:

 1 <dependencyManagement>
 2     <dependencies>
 3         <!-- Override Spring Data release train provided by Spring Boot -->
 4         <dependency>
 5             <groupId>org.springframework.data</groupId>
 6             <artifactId>spring-data-releasetrain</artifactId>
 7             <version>Fowler-SR2</version>
 8             <type>pom</type>
 9             <scope>import</scope>
10         </dependency>
11         <dependency>
12             <groupId>org.springframework.boot</groupId>
13             <artifactId>spring-boot-dependencies</artifactId>
14             <version>2.1.3.RELEASE</version>
15             <type>pom</type>
16             <scope>import</scope>
17         </dependency>
18     </dependencies>
19 </dependencyManagement>

2.2安装Spring Boot CLI

Spring Boot CLI(命令行界面)是一个命令行工具,您可以使用它来快速使用Spring进行原型设计。它允许您运行Groovy脚本,这意味着您拥有熟悉的类似Java的语法,而没有太多的样板代码。您不需要使用CLI来使用Spring Boot,但它绝对是实现Spring应用程序的最快方法。

2.2.1手动安装

下载压缩包,解压,参照INSTALL.txt安装即可,Windows系统建议使用配置环境变量的方法
https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.1.3.RELEASE/spring-boot-cli-2.1.3.RELEASE-bin.zip
https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.1.3.RELEASE/spring-boot-cli-2.1.3.RELEASE-bin.tar.gz

 3开发第一个Spring Boot工程

3.1maven实现第一个SpringBoot工程

原文地址:https://www.cnblogs.com/ShouWangYiXin/p/10405827.html