What is spring-boot-starter-parent in Spring-Boot pom.xml file?
We have seen that spring-boot application pom.xml has parent declaration as shown in the below pom.xml file.
Why do we need that?
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.java2novice.springboot</groupId>
<artifactId>spring-boot-tutorials</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
</project>
|
As we know, in general, parent pom declarations allows us to manage following things for multiple child projects.
- Configuration: It allows us to maintain consistancy in terms of java version and other related properties accross all sub projects.
- Depedency Management: This will control all versions of the dependencies to avoid dependency version conflicts.
- Default Plugin Configuration
So based on the above understanding, spring boot also requires parent declarations to define all spring boot
dependencies into the project. It inherits dependency management from spring-boot-dependencies.
You should only need to specify the Spring Boot version number on this dependency.
If you import additional starters, you can safely omit the version number.
Now, based on your project requirement, you would declare dependencies to one or more “Starters” jars. For instance,
in our hello world example, we will be developing a MVC app. So we will include spring-boot-starter-web. Resulting POM should look like:
<!-- Adds Tomcat and Spring MVC, along others -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
|
|