从这篇文章开始以spring boot2为主要版本进行使用介绍。
Spring boot 2特性
spring boot2在如下的部分有所变化和增强,相关特性在后续逐步展开。
特性增强
基础组件升级:
spring framework 5
Metrics
Security
使用变化
依赖条件
以当前GA版本的spring boot 2.0.6为例,其依赖条件如下:
Servlet容器
支持的servlet容器信息如下:
pom.xml
按照如下方式设定pom文件
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.liumiaocn</groupId> <artifactId>springbootdemo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>springbootdemo</name> <description>spring boot demo project</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
SpringbootdemoApplication
liumiaocn:springbootdemo liumiao$ cat src/main/java/com/liumiaocn/springbootdemo/SpringbootdemoApplication.java package com.liumiaocn.springbootdemo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RequestMapping; @RestController @SpringBootApplication public class SpringbootdemoApplication { @RequestMapping("/") String home() { return "Hello, Spring Boot 2"; } public static void main(String[] args) { SpringApplication.run(SpringbootdemoApplication.class, args); } } liumiaocn:springbootdemo liumiao$
SPRING INITIALIZR
也可以使用SPRING INITIALIZR快速创建spring boot项目,因为以前的文章中已经解释过,此处不再赘述。
编译&构建&运行
编译&构建
编译命令:mvn install
运行
运行命令:java -jar target/springbootdemo-0.0.1-SNAPSHOT.jar
结果确认
liumiaocn:springbootdemo liumiao$ curl http://localhost:8080 Hello, Spring Boot 2liumiaocn:springbootdemo liumiao$
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接