SpringBoot學習筆記(五)--HelloWorld細節-場景啓動器(Starters)

父項目

通過了解 spring initializr 生成的工程中 pom.xml 文件的內容,可以發現其依賴了一個父項目:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

找到 spring-boot-starter-parent-2.3.0.RELEASE.pom 的源碼後,發現它所依賴的父項目:

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-dependencies</artifactId>
  <version>2.3.0.RELEASE</version>
  <relativePath>../../spring-boot-dependencies</relativePath>
</parent>

spring-boot-dependencies 用於管理 Spring Boot 應用裏面所有依賴的版本,即 Spring Boot 的版本仲裁中心。以後我們導入依賴時,默認是不需要寫版本,但是沒有在 dependencies 裏面管理的依賴,需要聲明版本號。

啓動器 Starters

通過了解 spring initializr 生成的工程中 pom.xml 文件的內容,可以發現一個啓動器:

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

官網對 Starters 的介紹

Starters are a set of convenient dependency descriptors that you can include in your application. You get a one-stop shop for all the Spring and related technologies that you need without having to hunt through sample code and copy-paste loads of dependency descriptors. For example, if you want to get started using Spring and JPA for database access, include the spring-boot-starter-data-jpa dependency in your project.

The starters contain a lot of the dependencies that you need to get a project up and running quickly and with a consistent, supported set of managed transitive dependencies.

來源:

https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE/reference/html/using-spring-boot.html#using-boot-starter

啓動器 Starters 的作用

spring-boot-starter:spring-boot 場景啓動器,幫我們導入了 Web 模塊正常運行時所依賴的組件。

Spring Boot 將所有的功能場景都抽取出來,做成一個個的 Starters,只需要在項目中引入這些 Starters, 相關場景的所有依賴都會導入進來。要用什麼功能就導入什麼場景的啓動器。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章