springboot常見依賴說明

spring boot 雖然不強制使用特殊的依賴。但是其提供了一些非常高效的依賴。其中最有如下幾個:

  • spring-boot-starter-parent
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath/>
    </parent>

spring-boot-starter-parent這是一個依賴管理器的pom文件。它的作用就是管理boot需要的所有依賴,從而統一各種jar的版本號,避免了版本不一致而出現的問題。所以,引入其他的依賴就可以省略版本號。當然也可以加上指定的版本號,從而取代默認的。

  • spring-cloud-dependencies

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    spring-cloud-dependencies也是一個依賴管理器的pom文件,與spring-boot-starter-parent的作用一樣,不同的是spring-cloud-dependencies是對cloud的依賴管理。如:spring-cloud-starter-config、spring-cloud-starter-netflix-eureka-server

  • spring-boot-starter-web

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

    spring-boot-starter-web會自動嵌入tomcat容器。同時,springboot也會根據classpath中的dependency來自動配置。比如:spring-boot-starter-web會自動裝配tomcat容器;並且會自動從application.properties中讀取web應用的配置,如:server.port;如果application.properties沒有配置相關的參數,則採用默認的配置信息,如:8080。

  • spring-boot-starter-data-jpa數據庫連接的依賴。
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

spring-boot-starter-data-jpa數據庫連接的依賴。

  • spring-cloud-config-server

    <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
    </dependency>

    spring-cloud-config-server配置中心;

  • spring-cloud-starter-netflix-eureka-server
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>

    spring-cloud-starter-netflix-eureka-server註冊中心。是spring cloud的核心架構。

說明:spring boot提供的一系列spring-boot-starter-和spring-cloud-starter-依賴,其實是相關功能依賴的整合,即引入一個start依賴,就引入多個相應的jar。同時需要注意的是,spring boot提供的starter都是spring-boot-starter-和spring-cloud-starter-這樣開頭的,如果想自定義starter,則命名格式應該是:*-spring-boot-starter.

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