What is Spring boot starter parent

In this article, we will understand the spring-boot-starter-parent dependency which is a project starter.

Spring Boot Starters

While creating the big web application, there are a number of dependencies we need to add. The addition of dependency is an important aspect for any project but adding manually just increases the time. 

So, the Spring Boot came up with spring starters to address this issue. Spring Starters has around 50+ different starter modules.  It contains a set of dependency descriptors that we can add to our application.

In the Spring Boot framework, all the starters start with spring-boot-starter-* where * is the type of application.

Example: If we want to add Spring Web dependency to build a web application, we just need to have spring-boot-starter-web in the pom.xml file.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

Starters Templates

The following is the list of frequently used spring starters along with the description.

Name

Description

spring-boot-starter-web-services

It is used for Spring web services
spring-boot-starter-thymeleaf

It is used to add thymeleaf views

spring-boot-starter-data-couchbase

It is used to Couchbase document-oriented database

spring-boot-starter-mail

It is used to support Java mail

spring-boot-artemis

It is used for JMS messaging

spring-boot-starter-web

It is used for creating web applications.

spring-boot-starter-data-redis

It is used for Redis key-value data stores.

spring-boot-starter-data-gemfire

It is used in GemFire distributed data stores.

spring-boot-starter-activemq

It is used in JMS messaging using Apache ActiveMQ.
spring-boot-starter-data-rest

It is used to expose Spring Data repositories over REST.

spring-boot-starter-cache

It is used for spring Framework caching support.

spring-boot-starter-data-solr

It is used for the Apache Solr Search platform.

spring-boot-starter-batch

It is used for Spring Batch.

spring-boot-starter-freemarker

It is used to add freemarker views.

spring-boot-starter-security

It is used for spring security.

spring-boot-starter-aop

It is used for aspect-oriented programming.

spring-boot-starter-validation

It is used for Java bean validation using Hibernate Validator.

spring-boot-starter-mobile

It is used for building web applications using spring mobile.

spring-boot-starter-test

It is used for applications with libraries such as JUnit, Hamcrest, and Mockito.
spring-boot-starter-data-jpa

It is used for Spring Data JPA with Hibernate.

spring-boot-starter-data-mongodb

It is used for MongoDB document-oriented databases.
spring-boot-starter-cloud-connectors

It is used for Spring Cloud Connectors that simplify connecting to service in the Cloud.

spring-boot-starter-actuator

It is used for Spring Boot Actuator that provides us production-ready features.

spring-boot-starter-logging

It is used for logging using Logback.

spring-boot-starter-tomcat

It is used for Tomcat as the embedded servlet container.

spring-boot-starter-log4j2

It is used for Log4j2 for logging.
spring-boot-starter-jetty

It is used for Jetty as the embedded servlet container

Thus, these are some spring starters template available that increase the POM file manageability. It helps us to get production-ready, tested, dependency configuration. And more important It decreases the overall configuration. 

What is Spring-boot-starter-parent?

The spring-boot-starter-parent is a project starter. It is a dependency that is used internally all by Spring boot dependency.

  • In the POM file, it is the parent dependency that provides all plugin management for spring boot-based applications.
  • It provides all the default configurations for our application.
  • Spring-boot-starter-parent inherits dependency management from soring-boot dependency.

we can use the following in pom.xml to bootstrap the project: The version here can be changed.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.2</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

How to Manage dependency?

After we have declared spring-boot-starter-parent, we can have any dependencies from the parent by just declaring in the dependencies tag.

The benefit here is that Maven will download the jar based on the version define for the starter parent in the parent tag. (we don’t need to specify the version)

<dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
  • Here, we can see no version is mention in the dependency tag.
  • Only the artifactId and groupId are mentioned.

Spring Boot Starter Parent Internal

Let us see the default Parent POM: This file is the actual file that contains the information of the default version to use for all libraries.

<properties>  
<java.version>1.8</java.version>  
<resource.delimiter>@</resource.delimiter>   
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>  
<maven.compiler.source>${java.version}</maven.compiler.source>  
<maven.compiler.target>${java.version}</maven.compiler.target>  
</properties>

This is the default parent POM that is used by the Spring Boot framework. The properties section defined the application default values such as the Java version, encoding, source and etc.

Spring Boot Starter without Parent

There can be a requirement when we want to make the custom maven parent. So, Spring Boot gives us the flexibility to still use the dependency management without inheriting spring-boot-starter-parent.

Here, we can use the <scope>import</scope> tag for this.

<dependency>  
<!-- Importing dependency management from Spring Boot -->  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-dependencies</artifactId>  
<version>2.5.2.RELEASE</version>  
<type>pom</type>  
<scope>import</scope>  
</dependency>

Thus, this was all about Spring-boot-starter-parent which is nothing but a special project starter. In the next article of this tutorial, we will look at the starters template available.