项目地址: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或者更高