千家信息网

spring boot2.0的功能和特性详细介绍

发表于:2025-02-01 作者:千家信息网编辑
千家信息网最后更新 2025年02月01日,本篇内容主要讲解"spring boot2.0的功能和特性详细介绍",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"spring boot2.0的功能和特性详
千家信息网最后更新 2025年02月01日spring boot2.0的功能和特性详细介绍

本篇内容主要讲解"spring boot2.0的功能和特性详细介绍",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"spring boot2.0的功能和特性详细介绍"吧!

从这篇文章开始以spring boot2为主要版本进行使用介绍。

Spring boot 2特性

spring boot2在如下的部分有所变化和增强,相关特性在后续逐步展开。

特性增强

基础组件升级:

  • JDK1.8+

  • tomcat 8+

  • Thymeleaf 3

  • Hibernate 5.2

spring framework 5

  • Reactive Spring

  • Functional API

  • Kotlin支持

Metrics

Security

使用变化

  • 配置属性变化

  • Gradle插件

  • Actuator endpoints

依赖条件

以当前GA版本的spring boot 2.0.6为例,其依赖条件如下:

  • Maven: 3.2+

  • Gradle:4.x

Servlet容器

支持的servlet容器信息如下:

  • Tomcat 8.5: servlet3.1

  • Jetty 9.4: servlet 3.1

  • Undertow 1.4: servlet 3.1

pom.xml

按照如下方式设定pom文件

pom.xml文件详细如下:

 4.0.0 com.liumiaocn springbootdemo 0.0.1-SNAPSHOT jar springbootdemo spring boot demo project  org.springframework.boot spring-boot-starter-parent 2.0.6.RELEASE     UTF-8 UTF-8 1.8     org.springframework.boot  spring-boot-starter-web    org.springframework.boot  spring-boot-starter-test  test        org.springframework.boot  spring-boot-maven-plugin    

SpringbootdemoApplication

liumiaocn:springbootdemo liumiao$ cat src/main/java/com/liumiaocn/springbootdemo/SpringbootdemoApplication.javapackage 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@SpringBootApplicationpublic class SpringbootdemoApplication {    @RequestMapping("/")    String home() {     return "Hello, Spring Boot 2";    } public static void main(String[] args) { SpringApplication.run(SpringbootdemoApplication.class, args); }}liumiaocn:springbootdemo liumiao$
  • RestController和RequestMapping注解都是Spring MVC的注解,用于快速设定路由跳转信息

  • SpringBootApplication注解用于入口类,也是保证junit测试能够进行的条件之一。

SPRING INITIALIZR

也可以使用SPRING INITIALIZR快速创建spring boot项目,因为以前的文章中已经解释过,此处不再赘述。

访问地址:https://start.spring.io/

编译&构建&运行

编译&构建

编译命令:mvn install

运行

运行命令:java -jar target/springbootdemo-0.0.1-SNAPSHOT.jar

  • 或者使用mvn命令:mvn spring-boot:run

结果确认

liumiaocn:springbootdemo liumiao$ curl http://localhost:8080Hello, Spring Boot 2liumiaocn:springbootdemo liumiao$

到此,相信大家对"spring boot2.0的功能和特性详细介绍"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

0