最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot的依賴管理配置

 更新時(shí)間:2022年07月16日 09:10:31   作者:悠然予夏  
一般來講SpringBoot項(xiàng)目是不需要指定版本,而SSM項(xiàng)目是需要指定版本,SpringBoot的核心依賴就是spring-boot-starter-parent和spring-boot-starter-web兩個(gè)依賴,關(guān)于這兩個(gè)依賴的相關(guān)介紹具體今天小編給大家介紹下
  • 問題1:為什么導(dǎo)入dependency時(shí)不需要指定版本?

在Spring Boot入門程序中,項(xiàng)目pom.xml文件有兩個(gè)核心依賴,分別是spring-boot-starterparent和spring-boot-starter-web,關(guān)于這兩個(gè)依賴的相關(guān)介紹具體如下:

1.spring-boot-starter-parent依賴

在chapter01項(xiàng)目中的pom.xml文件中找到spring-boot-starter-parent依賴,示例代碼如下:

<!-- Spring Boot父項(xiàng)目依賴管理 -->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent<11./artifactId>
    <version>2.2.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

上述代碼中,將spring-boot-starter-parent依賴作為Spring Boot項(xiàng)目的統(tǒng)一父項(xiàng)目依賴管理,并將項(xiàng)目版本號(hào)統(tǒng)一為2.2.2.RELEASE,該版本號(hào)根據(jù)實(shí)際開發(fā)需求是可以修改的。

使用“Ctrl+鼠標(biāo)左鍵”進(jìn)入并查看spring-boot-starter-parent底層源文件,發(fā)現(xiàn)spring-bootstarter-parent的底層有一個(gè)父依賴spring-boot-dependencies,核心代碼具體如下

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

繼續(xù)查看spring-boot-dependencies底層源文件,核心代碼具體如下:

<properties>
    <activemq.version>5.15.11</activemq.version>
    ...
    <solr.version>8.2.0</solr.version>
    <mysql.version>8.0.18</mysql.version>
    <kafka.version>2.3.1</kafka.version>
    <spring-amqp.version>2.2.2.RELEASE</spring-amqp.version>
    <spring-restdocs.version>2.0.4.RELEASE</spring-restdocs.version>
    <spring-retry.version>1.2.4.RELEASE</spring-retry.version>
    <spring-security.version>5.2.1.RELEASE</spring-security.version>
    <spring-session-bom.version>Corn-RELEASE</spring-session-bom.version>
    <spring-ws.version>3.0.8.RELEASE</spring-ws.version>
    <sqlite-jdbc.version>3.28.0</sqlite-jdbc.version>
    <sun-mail.version>${jakarta-mail.version}</sun-mail.version>
    <tomcat.version>9.0.29</tomcat.version>
    <thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
    <thymeleaf-extras-data-attribute.version>2.0.1</thymeleaf-extras-dataattribute.version>
    ...
</properties>

從spring-boot-dependencies底層源文件可以看出,該文件通過標(biāo)簽對(duì)一些常用技術(shù)框架的依賴文件進(jìn)行了統(tǒng)一版本號(hào)管理,例如activemq、spring、tomcat等,都有與Spring Boot 2.2.2版本相匹配的版本,這也是pom.xml引入依賴文件不需要標(biāo)注依賴文件版本號(hào)的原因。

需要說明的是,如果pom.xml引入的依賴文件不是 spring-boot-starter-parent管理的,那么在pom.xml引入依賴文件時(shí),需要使用標(biāo)簽指定依賴文件的版本號(hào)。

  • 問題2: spring-boot-starter-parent父依賴啟動(dòng)器的主要作用是進(jìn)行版本統(tǒng)一管理,那么項(xiàng)目行依賴的JAR包是從何而來的?

2.spring-boot-starter-web依賴

查看spring-boot-starter-web依賴文件源碼,核心代碼具體如下

 <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
      <version>2.7.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-json</artifactId>
      <version>2.7.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <version>2.7.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>5.3.21</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.3.21</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

從上述代碼可以發(fā)現(xiàn),spring-boot-starter-web依賴啟動(dòng)器的主要作用是提供Web開發(fā)場(chǎng)景所需的底層所有依賴。

正是如此,在pom.xml中引入spring-boot-starter-web依賴啟動(dòng)器時(shí),就可以實(shí)現(xiàn)Web場(chǎng)景開發(fā),而不需要額外導(dǎo)入Tomcat服務(wù)器以及其他Web依賴文件等。當(dāng)然,這些引入的依賴文件的版本號(hào)是由spring-boot-starter-parent父依賴進(jìn)行的統(tǒng)一管理。

Spring Boot除了提供有上述介紹的Web依賴啟動(dòng)器外,還提供了其他許多開發(fā)場(chǎng)景的相關(guān)依賴,我們可以打開Spring Boot官方文檔,搜索“Starters”關(guān)鍵字查詢場(chǎng)景依賴啟動(dòng)器

列出了Spring Boot官方提供的部分場(chǎng)景依賴啟動(dòng)器,這些依賴啟動(dòng)器適用于不同的場(chǎng)景開發(fā),使用時(shí)只需要在pox.xml文件中導(dǎo)入對(duì)應(yīng)的依賴啟動(dòng)器即可。

需要說明的是,Spring Boot官方并不是針對(duì)所有場(chǎng)景開發(fā)的技術(shù)框架都提供了場(chǎng)景啟動(dòng)器,例如數(shù)據(jù)庫操作框架MyBatis、阿里巴巴的Druid數(shù)據(jù)源等,Spring Boot官方就沒有提供對(duì)應(yīng)的依賴啟動(dòng)器。為了充分利用Spring Boot框架的優(yōu)勢(shì),在Spring Boot官方?jīng)]有整合這些技術(shù)框架的情況下,MyBatis、Druid等技術(shù)框架所在的開發(fā)團(tuán)隊(duì)主動(dòng)與Spring Boot框架進(jìn)行了整合,實(shí)現(xiàn)了各自的依賴啟動(dòng)器,例如mybatis-spring-boot-starter、druid-spring-boot-starter等。我們?cè)趐om.xml文件中引入這些第三方的依賴啟動(dòng)器時(shí),切記要配置對(duì)應(yīng)的版本號(hào)。

到此這篇關(guān)于SpringBoot的依賴管理配置的文章就介紹到這了,更多相關(guān)SpringBoot 依賴管理內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

宣恩县| 井冈山市| 榆中县| 宜春市| 杭锦旗| 修武县| 龙州县| 镇巴县| 红原县| 娄烦县| 北京市| 白水县| 大渡口区| 合川市| 沂水县| 江西省| 北京市| 焉耆| 平顶山市| 腾冲县| 大英县| 南乐县| 南和县| 蕉岭县| 青岛市| 澳门| 乌拉特后旗| 中山市| 沂水县| 佛学| 监利县| 荃湾区| 南召县| 昔阳县| 双峰县| 密云县| 华安县| 揭阳市| 延安市| 涿州市| 集贤县|