Home > Java > javaTutorial > SpringBoot dependency management configuration method

SpringBoot dependency management configuration method

王林
Release: 2023-05-10 15:19:12
forward
1013 people have browsed it

In the Spring Boot entry program, the project pom.xml file has two core dependencies, namely spring-boot-starterparent and spring-boot-starter-web. The relevant introduction to these two dependencies is as follows:

1. spring-boot-starter-parent dependency

Find the spring-boot-starter-parent dependency in the pom.xml file in the chapter01 project. The sample code is as follows:

<!-- Spring Boot父项目依赖管理 -->
<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>
Copy after login

In the above code, The spring-boot-starter-parent dependency serves as the unified parent project dependency management of the Spring Boot project, and unifies the project version number to 2.2.2.RELEASE. This version number can be modified according to actual development needs.

Use "Ctrl left mouse button" to enter and view the underlying source file of spring-boot-starter-parent. It is found that the underlying source file of spring-bootstarter-parent has a parent dependency spring-boot-dependencies. The core code is as follows

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

Continue to view the underlying source files of spring-boot-dependencies. The core code is as follows:

<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>
Copy after login

As can be seen from the underlying source files of spring-boot-dependencies, this file uses tags to support some common technologies. The dependency files of the framework have unified version number management, such as activemq, spring, tomcat, etc., all have versions that match the Spring Boot 2.2.2 version. This is why pom.xml does not need to mark the dependency file version number when introducing dependency files. .

It should be noted that if the dependency file introduced by pom.xml is not managed by spring-boot-starter-parent, then when pom.xml introduces the dependency file, you need to use a label to specify the version number of the dependency file.

  • Question 2: The main function of the spring-boot-starter-parent parent dependency starter is to perform unified version management. So where does the JAR package that the project line depends on come from?

2. spring-boot-starter-web dependency

View spring-boot-starter-web dependency file source code, the core code is as follows

 <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>
Copy after login

It can be found from the above code that spring-boot-starter-web The main function of the dependency launcher is to provide all the underlying dependencies required for web development scenarios.

Just like this, when the spring-boot-starter-web dependency starter is introduced in pom.xml, Web scenario development can be realized without the need to additionally import the Tomcat server and other Web dependency files. Of course, the version numbers of these imported dependency files are uniformly managed by the spring-boot-starter-parent parent dependency.

In addition to the Web dependency starter introduced above, Spring Boot also provides related dependencies for many other development scenarios. We can open the official Spring Boot documentation and search for the "Starters" keyword to query the scenario dependency starter.

SpringBoot dependency management configuration method

Lists some of the scenario dependency starters officially provided by Spring Boot. These dependency starters are suitable for different scenario development and only need to be used in the pox.xml file. Just import the corresponding dependency starter.

It should be noted that Spring Boot official does not provide scenario launchers for all technical frameworks developed in scenarios, such as the database operation framework MyBatis, Alibaba's Druid data source, etc. Spring Boot official does not provide them. The corresponding dependency starter. In order to make full use of the advantages of the Spring Boot framework, when Spring Boot officially did not integrate these technical frameworks, the development teams of technical frameworks such as MyBatis and Druid took the initiative to integrate with the Spring Boot framework and implement their respective dependency starters, such as mybatis-spring-boot-starter, druid-spring-boot-starter, etc. When we introduce these third-party dependency starters in the pom.xml file, remember to configure the corresponding version number.

The above is the detailed content of SpringBoot dependency management configuration method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template