GrabObject

Spring Boot Starters

Spring Boot starters are dependency descriptors which can be used in your project. Spring Boot starters make the task of defining all dependencies for your project simple.

Every developer faces difficulty and confusion in figuring out the dependent jars and finding out their definitions when writing dependency descriptor definitions for each and every jar required for their projects. Especially it takes some time and effort in finding the latest and correct version. Sometimes, even after careful analysis and inclusion of dependency descriptor of jars, when you run your app, you may get class not found exceptions due to missing jars. Again, it takes time to find about missing jars and the right version of jar to fix the issue.

To eliminate these issues and help developers build applications fast and reduce the work involved in dependency setup, spring boot provides starter dependency descriptors. Depending on the spring features or other third party frameworks you want use in your project, you can include the starters in your project to setup your project fast. You can find pom.xml of all starters here

Spring Boot Starter Parent

To setup maven for your Spring Boot project, you can use spring-boot-starter-parent starter. You need to add it as parent in your pom.xml. It defines maven defaults for your Spring Boot project.

Here is how you add spring-boot-starter-parent to your project pom.xml.

<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.zoftino.spring.boot.examples</groupId>
  <artifactId>boot-example-one</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>boot-example-one</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.5.RELEASE</version>
	</parent>
   …………..

Spring Boot Starter

Starter spring-boot-starter defines common dependency jars such as spring-boot, spring-boot-autoconfigure, spring-core, etc.. Other starters use spring-boot-starter to add common dependency definitions.

<dependencies>
			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot</artifactId>
			</dependency>
			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-autoconfigure</artifactId>
			</dependency>
			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-starter-logging</artifactId>
			</dependency>
			<dependency>
				<groupId>javax.annotation</groupId>
				<artifactId>javax.annotation-api</artifactId>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-core</artifactId>
			</dependency>
			<dependency>
				<groupId>org.yaml</groupId>
				<artifactId>snakeyaml</artifactId>
				<scope>runtime</scope>
			</dependency>
</dependencies>

Spring Boot Starters

There are starter definitions for various frame works. Depending on what you use in your project, you can pick them and add them to your project pom.xml. For example, if you want to use spring JDBC, simply add spring-boot-starter-jdbc starter to your project. Here is the pom with spring-boot-starter-jdbc starter dependency.

<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.zoftino.spring.boot.examples</groupId>
	<artifactId>boot-example-one</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>boot-example-one</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.5.RELEASE</version>
	</parent>

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

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

Below screenshot shows list of dependent jars added to class path of a project with the pom.xml shown above.

spring boot starters

To know the list of available starters, please visit spring boot project starters page on github. Names of the starters are self explanatory so you can easily find the starter artificatIds for features you want to include in your project.