1. 程式人生 > 實用技巧 >SpringBoot之優勢及應用場景

SpringBoot之優勢及應用場景

一、優勢

1、簡化編碼

假如要建立一個web應用,在使用spring的時候,都需要在pom檔案中新增多個依賴,而springboot則幫助我們啟動一個web容器,在springboot中我們只需要在pom檔案中新增一個starter-web依賴即可。

<dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
</dependency>

點開看看,springboot的starter-web包含了多個依賴,包括之前在spring工程中匯入的依賴,其中一部分依賴如下:

<!-- .....省略其他依賴 -->
<dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>5.1.8.RELEASE</version>
      <scope>compile</scope>
</dependency>
<dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.1.8.RELEASE</version>
      <scope>compile</scope>
</dependency>

由此可見,springboot大大簡化了我們的編碼,之前匯入多個依賴,現在只需匯入一個依賴即可。

2、 簡化部署

在使用springmvc時,專案部署時我們需要在伺服器上部署tomact或其他web應用伺服器,然後把專案打成war包放到web容器中去。使用springboot後,我們不再需要在伺服器上部署tomact,因為springboot內嵌了tomact伺服器,只需要將專案打成jar包,使用java -jar xxx.jar 一鍵式啟動專案。同時也降低對執行環境的而基本要求,環境變數中有jdk即可。

3、簡化配置

4、簡化監控

二、應用場景