How to introduce springboot-related dependencies in Maven
1. Do not use version management (not recommended)
If there is no unified version management in the project, then each dependency must be explicitly declared<version>
。
Example:
<dependency> <groupId></groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.7.4</version> </dependency> <dependency> <groupId></groupId> <artifactId>spring-boot-devtools</artifactId> <version>2.7.4</version> </dependency>
⚡ Disadvantages: Manually specified, error-prone, not recommended.
2. Use version management (recommended)
2.1 Inherit spring-boot-starter-parent
Direct inheritance in :
<parent> <groupId></groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.4</version> </parent>
Then when adding dependencies, no need to write<version>
:
<dependency> <groupId></groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
2.2 Use spring-boot-dependencies + to customize parent project
If you want to use Spring Boot's unified version management because the company project has a custom parent POM, you can<dependencyManagement>
Import in:
<dependencyManagement> <dependencies> <dependency> <groupId></groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.7.4</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Then when adding dependencies, there is no need to write again<version>
。
2.3 Introducing spring-framework-bom
Sometimes, projects need to control the module versions of Spring Framework separately. For example, in some JDK8 projects, if you want Spring Framework to use the latest compatible versions as much as possible, you can introduce spring-framework-bom to specifically manage the dependency version of Spring Framework.
Example:
<dependencyManagement> <dependencies> <dependency> <groupId></groupId> <artifactId>spring-framework-bom</artifactId> <version>${}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Then you can introduce the specific modules of Spring Framework as follows without writing a separate version:
<dependency> <groupId></groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId></groupId> <artifactId>spring-web</artifactId> </dependency>
⚡ Note:
- spring-framework-bom only manages the Spring Framework itself (such as spring-core, spring-web, spring-context), and does not include Spring Boot's starter or other automatic configuration modules.
- spring-boot-dependencies not only manage their own things (the Spring Framework itself mentioned above), but also helps you manage external partners, such as Jackson, Tomcat, MySQL driver, Redis client, etc.
This is the end of this article about how to introduce springboot-related dependencies in Maven (the latest recommendation). For more related contents of Maven's introduction of springboot-related dependencies, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!