SpringBoot dependency management

Generally speaking, SpringBoot projects do not need to specify the version, while SSM projects do need to specify the version. The core dependencies of SpringBoot are spring-boot-starter-parent and spring-boot-starter-web. These two dependencies are described below

spring-boot-starter-parent

<! Spring Boot parent project dependency Management -->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.1</version>
    <relativePath/>
</parent>
Copy the code

In the above code, the spring-boot-starter-parent dependency is used as the unified parent project dependency management of the SpringBoot project, and the project version is unified as 2.6.1.RELEASE. The version number can be changed according to actual development scenarios.

Click to enter the spring-boot-starter-parent underlying source file, and you can find the following content

<! -- Parent dependency -->
<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-dependencies</artifactId>
  <version>2.6.1</version>
</parent>


<properties>
  <java.version>1.8</java.version>
  <resource.delimiter>@</resource.delimiter>
  <maven.compiler.source>${java.version}</maven.compiler.source>
  <maven.compiler.target>${java.version}</maven.compiler.target>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
Copy the code

Spring-boot-starter-parent dependencies include spring-boot-parent dependencies. The properties properties are mainly used to set common properties, such as Java version 1.8 by default, Maven compiled version 1.8 by default, and utF-8 character set for the project.

Click on the source file of Spring-boot-Dependencies and find the following information

Spring-boot-dependencies dependencies file (ActiveMQ, Spring, Kafka, okHttp3, etc.) Both have versions that match SpringBoot version 2.6.1, which is why pom.xml introduces dependency files that do not need to be marked with dependency file version numbers. Note that if pom.xml imports a dependency file that is not managed by spring-boot-starter-parent, the version tag is used to specify the version number of the dependency file when pom.xml imports the dependency file.

spring-boot-starter-web

View the source code of the spring-boot-starter-web dependency file. The core code is as follows

<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <version>2.6.1</version>
    <scope>compile</scope>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-json</artifactId>
    <version>2.6.1</version>
    <scope>compile</scope>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <version>2.6.1</version>
    <scope>compile</scope>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.3.13</version>
    <scope>compile</scope>
  </dependency>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.3.13</version>
    <scope>compile</scope>
  </dependency>
</dependencies>
Copy the code

As you can see from the code above, the primary role of the Spring-boot-starter-Web dependency is to provide all the low-level dependencies needed for a Web development scenario.

Therefore, when spring-boot-starter-web dependencies are introduced in pum.xml, web scenarios can be developed without the need to import additional Tomcat servers and other Web dependency files. The version numbers of these imported dependency files are managed uniformly by the spring-boot-starter-parent parent dependency.

conclusion

As you can see from the two examples above, SpringBoot provides dependencies for many other development scenarios. You can go to the Official SpringBoot documentation and search for “Starters” for scenariodependent Starters

SpringBoot starter

As there are many officially provided dependent initiators, only part of the scenario dependent initiators are listed. These dependent initiators are applicable to the development of different scenarios, and you only need to import the corresponding dependent initiators into the POX. XML file to use them.

Note: SpringBoot does not officially provide the scene startup period for all technical frameworks developed for all scenarios. For example, operating framework Mybatis, Alibaba Druid, etc., do not provide the corresponding dependent launcher. Other third party official teams took the initiative to integrate with the SpringBoot framework to release their own dependent boot periods.

Therefore, you must configure the version number of a third-party dependent initiator