Spring Boot - Starter Parent
Last Updated :
28 Jul, 2021
Spring Boot Starter Parent is a starter project that provides the default configuration for spring-based applications. It is added as a parent in the pom.xml file. The spring-boot-starter-parent defines spring-boot-dependencies as its parent. The spring-boot-starter-parent inherits dependency management from spring-boot-dependencies. Every Spring Boot release provides a list of dependencies and the latest versions it supports. The dependency management feature of the starter parent allows the common dependencies to omit the <version> tag in the pom.xml file. If a dependency requires a specific version other than the version configured by the starter parent, that can be added using the <version> tag. The following are the features of the starter parent project:
- The dependency management feature manages the versions of common dependencies.
- Provide the default compiler level as Java 1.8 and UTF-8 source encoding.
- Provides a default configuration for Maven plugins such as maven-surefire-plugin, maven-jar-plugin, and maven-failsafe-plugin.
- Executes a repackage goal with a repackage execution id.
- Resource filtering and configuring profile-specific files.
The parent of spring-boot-starter-parent looks like the following
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath>../../spring-boot-dependencies</relativePath>
</parent>
The following code has to be added in the pom.xml to use spring-boot-starter-parent as a parent project.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version> <!-- spring boot version number -->
<relativePath/> <!-- lookup parent from repository -->
</parent>
Managing dependencies
Any spring boot starter can be included under the dependencies section. If we omit the version for a particular starter, Maven will download the jar files based on the version number defined in the parent section. For example, if we require a data access layer, then we should add spring-data-jpa dependency starter in the pom.xml file.
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependencies>
Dependency Management Tag
If you require a different version of dependency provided by the spring-boot-starter-parent, we can add a particular version inside the <version></version> tag and include the dependency and its version inside the dependencyManagement section.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
</dependencyManagement>
Properties
We know that spring-boot-starter-parent configures the java compiler version, Maven plugins version, and Dependencies version using the properties defined inside it. We can override those property values inside the pom.xml file under the properties section. Suppose our project requires a different version of the sl4j library and a different java version.
<properties>
<java.version>1.8</java.version>
<slf4j.version>1.7.30</slf4j.version>
</properties>
Using Spring Boot Without a Starter Parent
If we want to inherit from the custom parent POM or define all the Maven configurations manually, we don't inherit from the spring-boot-starter-parent pom. However, we can still benefit from the dependency management feature(not the plugin management) provided by spring-boot-dependencies, by including the dependency inside the dependencyMangement section as an import scope.
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.5.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Note: To override the properties of individual dependencies, we need to add those dependencies prior to the addition of spring-boot-dependencies.
Similar Reads
Spring Boot - CRUD Operations CRUD stands for Create, Read/Retrieve, Update, and Delete and these are the four basic operations that we perform on persistence storage. CRUD is data-oriented and the standardized use of HTTP methods or there is a term for this called HTTP action verbs. HTTP has a few action verbs or methods that w
7 min read
Spring Boot - REST Example In modern web development, most applications follow the Client-Server Architecture. The Client (frontend) interacts with the server (backend) to fetch or save data. This communication happens using the HTTP protocol. On the server, we expose a bunch of services that are accessible via the HTTP proto
4 min read
How to Change the Default Port in Spring Boot? Spring Boot framework provides a default embedded server i.e. the Tomcat server for many configuration properties to run the Spring Boot application. The application runs on the default port which is 8080. As per the application need, we can also change this default port for the embedded server. In
4 min read
Spring Boot - Hello World Spring Boot is built on top of the Spring Framework and contains all the features of Spring. It has become a favorite of developers these days because of its rapid production-ready environment, which enables the developers to directly focus on the logic instead of struggling with the configuration a
4 min read
What is Command Line Runner Interface in Spring Boot? Spring Boot CLI (Command Line Interface) is a command line software or tool. This tool is provided by the Spring framework for quickly developing and testing Spring Boot applications from the command prompt. In this article, we will discuss the command line runner interface in the spring boot. Sprin
3 min read
How to Make a Simple RestController in Spring Boot? A RestController in Spring Boot is a specialized controller that is used to develop RESTful web services. It is marked with the @RestController annotation, which combines @Controller and @ResponseBody. This ensures that the response is automatically converted into JSON or XML, eliminating the need f
2 min read
How to Implement Simple Authentication in Spring Boot? In this article, we will learn how to set up and configure Basic Authentication with Spring. Authentication is one of the major steps in any kind of security. Spring provides dependencies i.e. Spring Security that helps to establish the Authentication on the API. There are so many ways to add Authen
4 min read
What is PathVariable in the Spring Boot? Java language is one of the most popular languages among all programming languages. There are several advantages of using the java programming language, whether for security purposes or building large distribution projects. One of the advantages of using JAVA is that Java tries to connect every conc
3 min read
How to Create a Spring Boot Project in Spring Initializr and Run it in IntelliJ IDEA? Java language is one of the most popular languages among all programming languages. There are several advantages of using the java programming language, whether for security purposes or building large distribution projects. One of the advantages of using Java is that it tries to connect every concep
3 min read
How to Get the Body of Request in Spring Boot? Java language is one of the most popular languages among all programming languages. There are several advantages of using the Java programming language, whether for security purposes or building large distribution projects. One of the advantages of using Java is that Java tries to connect every conc
4 min read