Spring Boot Starter Example

Spring Boot Starter Example

 

In this article, I am going to showing how to create a spring boot starter example project.

Pre-Requisites

  1. Java 1.8
  2. Spring Boot 2.2.5.RELEASE
  3. Eclipse IDE

Spring boot project can be created in multiple ways.

  1. Eclipse Maven
  2. STS
  3. start.spring.io

Here I am going to show start.spring.io using to create spring boot project.

Step 1:

Open any browser in your system and type https://start.spring.io/ in the address bar

Spring-Boot-1

Spring-Boot-1

 

Step 2:

Project:  Maven Project

Language: Java

Spring Boot:  2.2.5

Project Metadata :

Group: com.narayanatutorial

Artifact: SpringBootStarterExample

Dependencies: nothing select because by default spring started included.

Click on Generate – Ctrl + button to generate and download the project.

Spring-Boot-2

Spring-Boot-2

 

 

Step 3:

Unzip the downloaded project in your system and then import it into eclipse as maven project.

Open Eclipse, go to File -> Import -> Maven ->  Existing Maven Projects –> click on Next — > browse the unzipped folder and then click on finish.

Spring-Boot-Maven-Import

Spring-Boot-Maven-Import

 

Step 4:

The project was imported successfully and then execute the main java program.

 

Source Code:

SpringBootStarterExampleApplication.java

package com.narayanatutorial.SpringBootStarterExample;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootStarterExampleApplication {

	public static void main(String[] args) {
		System.out.println("Hello World");
		SpringApplication.run(SpringBootStarterExampleApplication.class, args);
		
	}

}

 

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.2.5.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.narayanatutorial</groupId>
	<artifactId>SpringBootStarterExample</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>SpringBootStarterExample</name>
	<description>Demo project for Spring Boot</description>
	<packaging>jar</packaging>

	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</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>
				<configuration>
				<mainClass>com.narayanatutorial.SpringBootStarterExample.SpringBootStarterExampleApplication</mainClass>
				</configuration>
			</plugin>
		</plugins>
	</build>

</project>

 

Get full source code from git.

 

 

 

Leave a Reply