Boot

Spring Boot Starter Tutorial

This is a tutorial about Spring Boot Starter.

1. Introduction

Spring Boot is a Spring Framework module that provides Rapid Application Development or RAD for spring projects. In this article, we look at one of Spring Boot’s features called Spring Boot Starters.

2. What is a Spring Boot Starter?

Without Spring Boot starters, we need to add all the necessary dependencies and versions in the pom. With Spring Boot Starter, we need to add just the starter name in the pom. Then all the related dependencies get added automatically to the project. Hence, Spring Boot starters are called dependency descriptors.

Spring Boot provides many starters under the group org.springframework.boot. Their names all start with spring-boot-starter*. The way we add a starter to our application is by using the pom.xml

The most commonly used starters are application starters. They help to develop a specific type of application. For example, we can quickly build Spring applications with web services if we use the spring-boot-starter-web starter. The way we add an application starter to our pom.xml is as follows:

 
  <dependency>
     <groupid > org.springframework.boot</groupid>
     <artifactid>spring-boot-starter-web</artifactid>
  </dependency>

There are 3 main types of Spring Boot starters. we take a look at each below.

3. Spring Boot Application Starters

When we include any starter in our pom.xml, Spring will download all the dependencies required for that functionality without having to explicitly add them to our pom.xml. For example, in the above example, Spring would download all the web application dependencies. There are a large number of application starters that Spring supports. Given below is their list:

Starter NameDescription
spring-boot-starter-thymeleafMVC web applications with Thymeleaf for views.
spring-boot-starter-data-couchbaseCouchbase document-oriented database and Spring Data Couchbase.
spring-boot-starter-artemisTo use Apache Artemis as the JMS messaging protocol.
spring-boot-starter-web-servicesSpring Web Services application.
spring-boot-starter-mailEmail sending applications. It also supports Javax mail API.
spring-boot-starter-data-redisRedis key-value data store, Spring Data Redis, and the Jedis client.
spring-boot-starter-webBuild web and RESTful Spring applications.
spring-boot-starter-data-gemfireGemFire distributed data store with the Spring Data GemFire.
spring-boot-starter-activemqApache ActiveMQ JMS messaging system.
spring-boot-starter-data-elasticsearchTo enable Elasticsearch search and analytics engine with Spring Data Elasticsearch.
spring-boot-starter-integrationSpring Integration.
spring-boot-starter-testSpring includes test libraries like JUnit, Hamcrest, and Mockito.
spring-boot-starter-jdbcTomcat JDBC connection pool for JDBC applications.
spring-boot-starter-mobileSpring Mobile web applications.
spring-boot-starter-validationHibernate Validator with Java Bean validator.
spring-boot-starter-hateoasSpring HATEOAS and MVC hypermedia-based RESTful web applications
spring-boot-starter-jerseyThis starter is an alternative starter to spring-boot-starter-web, which uses Tomcat by default. We can build RESTful applications using Jersey and JAX RS with this starter.
spring-boot-starter-data-neo4jIntegrate the Neo4j graph database with Spring Data Neo4j.
spring-boot-starter-data-ldapuse Spring Data LDAP.
spring-boot-starter-websocketSpring Framework’s WebSocket support-based WebSocket applications.
spring-boot-starter-aopUse Spring AOP and AspectJ for aspect-oriented programming.
spring-boot-starter-amqpuse Spring AMQP and Rabbit MQ.
spring-boot-starter-data-cassandraUse Cassandra distributed database with Spring Data Cassandra.
spring-boot-starter-social-facebookSpring Social Facebook.
spring-boot-starter-jta-atomikosJTA transactions using Atomikos.
spring-boot-starter-securitySpring Security.
spring-boot-starter-mustacheMVC web applications with Views using Mustache.
spring-boot-starter-data-jpaHibernate with Spring Data JPA.
spring-boot-starterThe starter is the primary starter that contains the basic configuration details.
spring-boot-starter-groovy-templatesMVC web applications with Views using Groovy.
spring-boot-starter-freemarkerMVC web applications with Views using Freemarker.
spring-boot-starter-batchTo enable batch jobs in spring.
spring-boot-starter-social-linkedinSpring Social LinkedIn.
spring-boot-starter-cacheSpring Framework’s caching mechanism.
spring-boot-starter-data-solrTo support apache Solr.
spring-boot-starter- data-mongodbTo use MongoDB document-oriented database with Spring Data MongoDB.
spring-boot-starter-jooqTo enable the use of jooq instead of jdbc for accessing SQL databases, we use this starter.
spring-boot-starter-jta-narayanaTo use the Spring Boot JTA Starter Narayana
spring-boot-starter-cloud-connectorsTo use Spring Cloud Connectors for cloud platforms like Cloud Foundry and Heroku.
spring-boot-starter-jta-bitronixTo enable Bitronix JTA transactions
spring-boot-starter-social-twitterSpring Social Twitter.
spring-boot-starter-data-restuse Spring Data with Spring Data REST.
Application starters

4. Third-Party Starters

Along with Spring Boot starters, we can also make custom starters as well. These starters are known as Third-party starters and their names generally do not start with spring-boot-starter*.

5. Spring Boot Production Starters and Technical Starters

Production Starters provide additional features to help you monitor and manage your application in production. Production starters are used for adding health metrics and monitoring to your application. The available ones are:

Starter nameDescription
spring-boot-starter-actuatorGet production-ready features for monitoring and managing applications.
Production Starters

Technical Starters are starters that provide functionality related to Web servers like Tomcat, Jetty, and logging.

Starter name Description
spring-boot-starter-undertowTo use Undertow as the embedded servlet container instead of the default Tomcat.
spring-boot-starter-jettyTo use Jetty as the embedded servlet container instead of the default Tomcat.
spring-boot-starter-loggingTo enable Logging capability.
spring-boot-starter-tomcatTo use Tomcat as the embedded servlet container. Tomcat is the default container used by the web starter.
spring-boot-starter-log4j2Enable Log4j2 logging.
Technical Starters

6. Spring Boot Parent

Every application has a set of default properties that all starters and dependencies use. The spring boot parent needs to be added for every Spring boot application. The way we add a spring boot parent starter in our project is as follows:

 
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.5</version>
    <relativePath/>
 </parent>

The Spring boot starter parent does the job of dependency and plugin management. It provides the default Java version, Spring Boot versions, and Maven plugins.  

7. Spring Boot Dependencies

Spring boot parent uses the spring dependencies. The spring-boot-dependencies contains a list of all dependencies it supports. The list of dependencies is available here.

Sometimes, in rare cases, we can skip adding the spring-boot-parent dependencies and do dependency management using the spring-boot-dependencies. The way we do this is by adding the following information in our pom.

<dependencyManagement>  
<dependencies>  
<dependency>    
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-dependencies</artifactId>  
<version>2.1.1.RELEASE</version>  
<type>pom</type>  
<scope>import</scope>  
</dependency>  
</dependencies>  
</dependencyManagement> 

8. Spring-Boot Starters Example

To understand how starters work, we have created a simple web-based “Hello World” Spring Boot project. The project has a Controller which displays a famous quote by Shakespeare. We have used Eclipse with Spring Tool Suite to create this project. The steps required to create this project are available here. In the pom.xml file, we have included the following starters:

  • spring-boot-starter-parent
  • spring-boot-starter-web
  • spring-boot-starter-test

These starters download all the required dependencies required to build a web-based Spring boot application. We can see the dependencies downloaded under the Maven dependencies in our project.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.4.5</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.jcg.examples.springbootstarters</groupId>
	<artifactId>springbootstarters</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>SpringBootStartersDemo</name>
	<description>Demo project for Spring Boot starters</description>
	<properties>
		<java.version>16</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>
spring boot starter - Maven Dependencies
Maven Dependencies

Since we have added the starters and hence resolved all required Maven dependencies, we can use all the spring-boot-specific annotations such as @Controller in our code. We do not have to worry about what jars to include, what versions to include, and so on. The starters help us set up and maintain dependencies in an easy,hassle-free method.

9. Summary

This article looked at what Spring Boot starters are and how we use them in our projects. They help make the tedious job of dependency and plugin management straightforward, hassle-free, and less error-prone.

11. Download the Source Code

The attached code is for the Simple Spring Boot application with starters for dependency management.

Download
You can download the full source code of this example here: Spring Boot Starter Tutorial

Reshma Sathe

I am a recent Master of Computer Science degree graduate from the University Of Illinois at Urbana-Champaign.I have previously worked as a Software Engineer with projects ranging from production support to programming and software engineering.I am currently working on self-driven projects in Java, Python and Angular and also exploring other frontend and backend technologies.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button