Alphalearningschool
        

<<< Prev

Next >>>

Up
Spring Boot Initializr

To Start with Spring Boot Initializr Project, you have to first visit Spring Initializr web page www.start.spring.io/ . Then, there you have to add dependencies that are required to develop your Spring Boot Initializr application along with group and artifact. You also need to provide your Spring Boot Version, Build and also platform to run your project.

              Here I have taken a simple example where I have added a few dependencies i.e. web.

 

After adding dependencies click on Generate Project button which will download you a zip file and the files will be extracted. After download is completed unzip the file.

Here we will be discussing about Maven Project.

Maven:

After unzipping, open your pom.xml file where you will find the below code.

<?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 http://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.1.1.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>demo</name>
	<description>Demo project for Spring Boot</description>

	<properties>
		<java.version>1.8</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>

 

Dependencies:

               By default Spring Boot provides a number of starters to add jars to your project. As in the above example, we have added only web dependency.

               Dependency we have added:

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

 

DemoApplication.java:

package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
}

 

This DemoApplication.java class must have a main method and must be declared with @SpringBootApplication annotation. As this class is having a main method, so the execution of Spring Boot Application starts from this point.