項目地址:http://projects.spring.io/spring-boot/html
Spring Boot使開發獨立的,產品級別的基於Spring的應用變得很是簡單,你只需"just run"。 咱們爲Spring平臺及第三方庫提 供開箱即用的設置,這樣你就能夠有條不紊地開始。多數Spring Boot應用須要不多的Spring配置。java
1:建立獨立的spring應用。 2:嵌入Tomcat, Jetty Undertow 並且不須要部署他們。 3:提供的「starters」poms來簡化Maven配置 4:儘量自動配置spring應用。 5:提供生產指標,健壯檢查和外部化配置 6:絕對沒有代碼生成和XML配置要求
咱們能夠經過繼承spring-boot-starter-parent來使用SpringBoot。git
其中涵蓋各種jar版本號,編碼等屬性配置,依賴配置,開發信息,協議,插件等管理信息。web
<!-- Inherit defaults from Spring Boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> </parent>
若是說咱們有本身的parent項目 咱們應該怎麼使用SpringBoot呢?spring
<dependencyManagement> <dependencies> <dependency> <!-- Import dependency management from Spring Boot --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.0.1.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
<dependencyManagement> <dependencies> <!-- Override Spring Data release train provided by Spring Boot --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-releasetrain</artifactId> <version>Fowler-SR2</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.0.1.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
SB包含了一個maven插件,能夠幫你打包成一個可執行的jar文件,使用方式以下apache
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
除了maven之外還支持ant和Gradle具體參閱 官方文檔tomcat
Staters是一組便捷的依賴描述,好比你想使用jpa功能,只須要引入spring-boot-starter-data-jpa 便可。其餘組件基本同樣,如spring-boot-starter-* 這種形式。app
具體參閱官方文檔
<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> <groupId>chapter01</groupId> <artifactId>chapter01</artifactId> <packaging>jar</packaging> <name>chapter01 Maven Webapp</name> <url>http://www.example.com</url> <!-- 引入parent依賴--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> </parent> <!--添加額外依賴 --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <!-- 打包 --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
package com.ricky; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; //開啓SpringBoot自動注入配置 等價於原來的SpringBootApplication @EnableAutoConfiguration //開啓RestController註解 含有ResponseBody 即非頁面形式 @RestController public class SpringBootApplication { @GetMapping("/") public String home() { return "Hello World!"; } /** * 開啓SpringBoot服務 * @param args */ public static void main(String[] args) { //等價於 new SpringApplication(SpringBootApplication.class).run(args); SpringApplication.run(SpringBootApplication.class,args); } }
容器相關
jdk
java8或者9
5.0.5.RELEASE或者更高