Spring Boot 原理分析

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-21 08:03:28

Spring Boot 原理分析

查看pom的parent节点

在这里插入图片描述
创建Spring Boot项目需要添加如下节点信息

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

按住Ctrl并单击“spring-boot-starter-parent”跳转至对应文件,发现又是一个pom文件

查看spring-boot-starter-parent对应pom文件

在这里插入图片描述

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.2.2.RELEASE</version>
    <relativePath>../../spring-boot-dependencies</relativePath>
  </parent>
.....
<build>
    <resources>
      <resource>
        <filtering>true</filtering>
        <directory>${basedir}/src/main/resources</directory>
        <includes>
          <include>**/application*.yml</include>
          <include>**/application*.yaml</include>
          <include>**/application*.properties</include>
        </includes>
      </resource>
	....
	</resources>
</build>

查看后并没有什么重要的信息,只有两个注意点

  1. parent节点
  2. build下的resource节点,用于加载用户自定义配置文件

这里继续按住Ctrl并点击parent节点,跳转至spring-boot-dependencies的pom文件

查看spring-boot-dependencies对应pom文件

在这里插入图片描述
进到这一层以后会发现没有parent节点了,说明追踪到根源了,下拉可以发现有三个主要节点

  • properties
  • dependencyManagement
  • build
    至此水落石出,当选定了SpringBoot的版本后,就会对应特定的parent节点,相应pom文件内以及提前配置好了需要导入的Jar包,以及相应的版本,保证了项目运行后不会产生冲突,也省去了反复配置的过程
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!