Spring Initializr

Spring Initializr is a lightweight extension to quickly generate a Spring Boot project. It helps you to customize your projects with configurations and manage Spring Boot dependencies.

  • It is a web application hosted at: https://start.spring.io.
  • It is the most simple way to create a Spring Boot application.
  • It has all the menu options for you, just choose them and use them in your application.

Let's see the below image of how the home page looks like:

Fig : Spring Initializr

As you can see, there are a number of options you need to fill in. They are:

  • Project type : Maven or Gradle
  • Language : Java, Kotlin, or Groovy
  • Spring Boot version : 2.6.7
  • Group : com.example
  • Artifact : demo
  • Name : demo
  • Description : Demo project for spring boot
  • Package Name : com.example.demo
  • Packaging : JAR
  • Java version : 1.8 or 11
  • After that, choose your application's dependencies from the menu.
  • Click the Generate Project button, and we have a ready-to-run application.

Here I am taking the project metadata as default, you can change those according to your project need. In dependencies, I have added Spring Web and Spring Boot Devtools.

Spring Initializr presents this project to you as a ZIP file, named as the value in the Artifact field, that is downloaded by your browser. In our case, this ZIP file is named demo.zip .

Let's unzip this file. We will now import this project into our favourite IDE. In Eclipse or STS, you can perform the following steps:

  • Launch Eclipse or STS.
  • Navigate to File | Import.
  • Choose the existing Maven projects.
  • Browse and select the folder that is the root of the Maven project (one containing the pom.xml file ).
  • Proceed with the defaults and click on Finish .
project structure
Fig : Spring Boot Project Structure

As you can see, there's very little code in this project and it also creates a couple of empty directories. The generated project contains the following:

  • pom.xml : A Maven build specification which contain all the dependencies of project.
  • DemoApplication.java : A class with a main() method to bootstrap the application.
  • DemoApplicationTests.java : An empty JUnit test class instrumented to load a Spring application context using Spring Boot auto-configuration.
  • application.properties : An empty properties file for you to add configuration properties.
  • static directory : Here, you can put any static content (JavaScript, style sheets, images, and so on) to be served from the web application.
  • templates directory : Here, you can put templates that render model data.