Spring Boot学习笔记03——pom.xml文件的那些事

不分轻重难易,碰到哪个说哪个!

(一)parent父项目
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
   <version>2.3.3.RELEASE</version>
   <relativePath/> <!-- lookup parent from repository -->
</parent>

Ctrl+左键 进入spring-boot-starter-parent,发现它还源于于另一个parent:

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

爸爸的爸爸叫爷爷!再Ctrl+左键 进入spring-boot-dependencies,发现里面有一个 属性:

<properties>
    <activemq.version>5.15.13</activemq.version>
    <antlr2.version>2.7.7</antlr2.version>
    <appengine-sdk.version>1.9.81</appengine-sdk.version>
    <artemis.version>2.12.0</artemis.version>
    <aspectj.version>1.9.6</aspectj.version>
    
    <-......此处省略100行 /->
    
    <webjars-locator-core.version>0.45</webjars-locator-core.version>
    <wsdl4j.version>1.6.3</wsdl4j.version>
    <xml-maven-plugin.version>1.0.2</xml-maven-plugin.version>
    <xmlunit2.version>2.7.0</xmlunit2.version>
  </properties>

这里定义了许许多多的依赖的版本号。
这个东西,也就是”爷爷“ 我们称它为”版本仲裁中心“,从此我们添加的依赖不需要指定版本号,版本仲裁中心自己决定要用哪个版本。(注意:这里可能会有特例)

(二)添加依赖

我们所有的第三方依赖都必须添加到这个目录下:

<dependencies>
      <- 依赖/->
</dependencies>

接下来看看我遇到的第一个依赖:

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

spring-boot-starter-web这句代码可以分为两个部分
前部分:spring-boot-starter,这东西叫:场景启动器
后部分:-web , 这东西是指:指定场景,这里就是web场景

Ctrl+左键 进入spring-boot-starter-web,发现它的源文件有这么多依赖:

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

这东西怎么理解呢?其实也就是spring-boot-starter场景启动器帮我们启动了web模块开发所需要的最基本最常见的依赖,不再需要我们去逐一添加依赖。
注: 场景启动器可以启动更多更多的场景,见官方文档。

(三)要将项目打包成可执行jar的必备标签
	<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

绝命三郎

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值