Here’s a step-by-step guide for creating your first Spring Boot project using Spring Initializr:
Step 1: Go to Spring Initializr
- Open the Spring Initializr website: https://start.spring.io/.
- You will see a friendly interface that allows you to configure your new Spring Boot project.
Step 2: Configure Your Project
- Project Settings:
- Project Type: Choose either
Maven
orGradle
(Maven is common for beginners). - Language: Select
Java
,Kotlin
, orGroovy
. Use Java for now to keep it simple. - Spring Boot Version: Select the latest stable version (e.g., 3.x.x).
- Project Type: Choose either
- Project Metadata:
- Group: Enter your domain or namespace (e.g.,
com.example
). - Artifact: This is the name of your project (e.g.,
demo
). - Name and Description: Optional, but you can customize these values.
- Package Name: Auto-generated from Group and Artifact but can be edited.
- Packaging: Choose
Jar
. - Java Version: Select the Java version installed on your machine (e.g., Java 23 for compatibility).
- Group: Enter your domain or namespace (e.g.,
- Dependencies:
- Click
Add Dependencies
and search for the necessary modules, such as:- Spring Web for building web applications (REST APIs, etc.).
- Spring Data JPA if you want database integration.
- H2 Database for testing with an in-memory database.
- Spring Boot DevTools for automatic application reload during development.
- Click
Add any additional dependencies you need for your project.
Step 3: Download the Project
- After configuring your project, click on the Generate button.
- A
.zip
file containing your project will be downloaded.
Step 4: Import the Project into IntelliJ IDEA
- Open IntelliJ IDEA.
- Go to File > Open and select the folder where you extracted your project.
- If IntelliJ suggests importing the project as a Maven/Gradle project, confirm the selection.
- Upon importing the project, IntelliJ will automatically resolve and download the dependencies.
Step 5: Run the Spring Boot Application
- Locate the main class in the project. It is usually located in
src/main/java/<package-name>
and has an@SpringBootApplication
annotation. - Right-click on the main class and select Run
. - Once the application starts, you will see the Spring Boot banner in the console and a log message indicating that the application started successfully.
Example Project Structure
Here’s a high-level view of what your project structure will look like:
src
├── main
| ├── java
| │ └── com.example.demo
| │ └── DemoApplication.java (Main class)
| └── resources
| ├── application.properties (Configuration file)
| ├── static
| └── templates
└── test
Next Steps
- Open the
application.properties
file in thesrc/main/resources/
directory to specify configuration data, such as database properties. - Start building your business logic, controller classes, and database entities.
Congratulations! 🎉 You’ve successfully created your first Spring Boot project using Spring Initializr.