Spring Boot Principle Deep-Dependent Management

Posted by joshi_v on Mon, 15 Jun 2020 21:30:25 +0200

2.2 Deep Principle

The traditional Spring framework implements a WEB service, which needs to import various dependent JAR packages, then write corresponding XML configuration files, etc. Compared with Spring Boot, it is more convenient, fast and efficient.So how does Spring Boot really do that?

2.2.1 Dependency Management

Question: Why doesn't Spring Boot need to specify a version when importing dependencies?

2.2.1.1 spring-boot-starter-parent
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.14.RELEASE</version>
</parent>

From the above, it can be seen that the spring-boot-starter-parent dependency is the unified parent project dependency management of the Spring Boot project, and the project version number is unified to 2.1.14.RELEASE, which can be modified based on actual development.

Entering the spring-boot-starter-parent underlying source file, we found that the underlying spring-boot-starter-parent has a parent dependency on spring-boot-dependencies

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

Continue to the spring-boot-dependencies underlying source file with the following core code

  <properties>
   ......
    <jolokia.version>1.6.2</jolokia.version>
    <jooq.version>3.11.12</jooq.version>
    <jsonassert.version>1.5.0</jsonassert.version>
    <json-path.version>2.4.0</json-path.version>
    <jstl.version>1.2</jstl.version>
    <jtds.version>1.3.1</jtds.version>
    <junit.version>4.12</junit.version>
    <junit-jupiter.version>5.3.2</junit-jupiter.version>
    <kafka.version>2.0.1</kafka.version>
    <kotlin.version>1.2.71</kotlin.version>
    <lettuce.version>5.1.8.RELEASE</lettuce.version>
    <liquibase.version>3.6.3</liquibase.version>
    <log4j2.version>2.11.2</log4j2.version>
    <logback.version>1.2.3</logback.version>
    <lombok.version>1.18.12</lombok.version>
  ......
    <spring.version>5.1.15.RELEASE</spring.version>
    <spring-amqp.version>2.1.14.RELEASE</spring-amqp.version>
    <spring-batch.version>4.1.4.RELEASE</spring-batch.version>
    <spring-cloud-connectors.version>2.0.7.RELEASE</spring-cloud-connectors.version>
    <spring-data-releasetrain.version>Lovelace-SR17</spring-data-releasetrain.version>
    <spring-framework.version>${spring.version}</spring-framework.version>
    <spring-hateoas.version>0.25.2.RELEASE</spring-hateoas.version>
    <spring-integration.version>5.1.10.RELEASE</spring-integration.version>
    <spring-kafka.version>2.2.13.RELEASE</spring-kafka.version>
    <spring-ldap.version>2.3.3.RELEASE</spring-ldap.version>
    <spring-plugin.version>1.2.0.RELEASE</spring-plugin.version>
    <spring-restdocs.version>2.0.4.RELEASE</spring-restdocs.version>
    <spring-retry.version>1.2.5.RELEASE</spring-retry.version>
    <spring-security.version>5.1.10.RELEASE</spring-security.version>
    <spring-session-bom.version>Bean-SR10</spring-session-bom.version>
    <spring-ws.version>3.0.9.RELEASE</spring-ws.version>
    <sqlite-jdbc.version>3.25.2</sqlite-jdbc.version>
 ......
  </properties>

From the underlying spring-boot-dependencies underlying source file, it can be seen that the file is tagged to unify version number management for some common technical framework dependency files, such as activemq, spring, lombok, etc., all have versions that match version 2.1.14.RELEASE, which is also known asPom.xmlThe reason why the dependent file does not need to be labeled depends on the jar version number is introduced.

Question: The spring-boot-starter-parent parent dependency starter is mainly used for unified version management. Where do the JAR packages on which the project runs come from?

2.2.1.2 spring-boot-starter-web

View spring-boot-starter-web source file source code

<dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
      <version>2.1.14.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-json</artifactId>
      <version>2.1.14.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <version>2.1.14.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate.validator</groupId>
      <artifactId>hibernate-validator</artifactId>
      <version>6.0.19.Final</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>5.1.15.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.1.15.RELEASE</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

As you can see from the code above, the spring-boot-starter-web dependency launcher is designed to provide all the underlying dependencies required for a web development scenario.

That's why, inPom.xmlWhen the spring-boot-starter-web dependency launcher is introduced, web scene development can be achieved without the need to import additional Tomcat server dependencies and other web dependency files.

Of course, these imported dependent file versions are still managed uniformly by spring-boot-starter-parent.

2.2.1.3 starter

In addition to providing the web dependency launcher described above, Spring Boot provides many of the dependencies required for scenarios


Listed are some of the startup dependencies provided by Spring Boot, as well as many that can be viewed from the spring official website.Depending on the scenario, we can use different business scenarios directly inPom.xmlIntroduce.

However, the Spring Boot website does not provide dependent starters for all scenarios, such as mybatis, druid, etc. However, in order to take full advantage of the advantages of the Spring Boot framework, the technical framework teams such as mybatis and Druid have actively integrated with the Spring Boot framework to achieve their own dependent starters.mybatis-spring-boot-starter, druid-spring-boot-starter.Direct at when neededPom.xmlYou can import from the file, but you need to manage the version number yourself.

Topics: Web Development Spring Junit kafka JSON