Spring Boot
参考文档
https://docs.spring.io/spring-boot/docs/current/reference/
参考代码
https://github.com/spring-projects/spring-boot/tree/v2.1.3.RELEASE/spring-boot-samples/
Features特征
- Create stand-alone Spring applications
- Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)
- Provide opinionated 'starter' dependencies to simplify your build configuration
- Automatically configure Spring and 3rd party libraries whenever possible
- Provide production-ready features such as metrics, health checks and externalized configuration
- Absolutely no code generation and no requirement for XML configuration
1. 创建独立的Spring应用程序
2. 嵌入的Tomcat,无需部署WAR文件
3. 简化Maven配置
4. 自动配置Spring
5. 提供生产就绪型功能,如指标,健康检查和外部配置
6. 绝对没有代码生成和对XML没有要求配置
System Requirements
Spring Boot 2.0.5.RELEASE requires Java 8 or 9 and Spring Framework 5.0.9.RELEASE or above.
Explicit build support is provided for the following build tools:
Build Tool | Version |
Maven | 3.2+ |
Gradle | 4.x |
Servlet Containers
Spring Boot supports the following embedded servlet containers:
Name | Servlet Version |
Tomcat 8.5 | 3.1 |
Jetty 9.4 | 3.1 |
Undertow 1.4 | 3.1 |
You can also deploy Spring Boot applications to any Servlet 3.1+ compatible container.
First 应用(idea2018)
创建mvn工程
pom.xml
<?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>
<groupId>com.mvnboot</groupId>
<artifactId>mvnboot</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<finalName>bootjarname</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
写代码(参考11.3 Writing the Code)
package com.mvnboot.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@SpringBootApplication
public class MvnBoot {
@RequestMapping("/")
String home() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(MvnBoot.class, args);
}
}
运行
运行结果
创建可执行jar包
运行jar包