If you're new to backend development in Java, Spring Boot is the perfect framework to begin your journey. It allows you to build robust, production-grade applications with minimal boilerplate code.
In this blog, Iβll guide you through creating your first Spring Boot project, understanding its folder structure, and building a basic REST APIβall with practical examples and screenshots.
π What is Spring Boot?
Spring Boot is an open-source Java framework designed to simplify Spring application development. It comes with built-in configurations, embedded servers, and dependency management to reduce boilerplate and speed up your development process.
π Key Benefits of Spring Boot
- Zero XML configuration
- Embedded Tomcat/Jetty/Undertow
- Auto-configuration for faster setup
- Powerful Spring ecosystem (Security, Data, Cloud, etc.)
β Step 1: Create Your Project Using Spring Initializr
Spring Initializr is a web-based generator for Spring Boot apps. Itβs fast, intuitive, and generates all the project boilerplate for you.
π₯οΈ Visit Spring Initializr
π§ Configure Your Project
Choose the following options:
- Project: Maven
- Language: Java
- Spring Boot Version: Latest stable (e.g., 3.2.x)
- Group:
com.example
- Artifact:
springboot-demo
- Name:
springboot-demo
- Description: A demo Spring Boot application
- Packaging: Jar
- Java: 17 or higher
π Add Dependencies
Click "Add Dependencies" and select:
- β Spring Web
- β Spring Boot DevTools (optional, for auto-restart)
- β Spring Data JPA (optional, for DB operations)
- β H2 Database (optional, for in-memory DB)
Then click "Generate" to download the .zip
file.
π Step 2: Open the Project in IntelliJ IDEA or Eclipse
π§ββοΈ Extract and Import
- Unzip the downloaded project.
- Open IntelliJ IDEA β File β Open β Select the extracted folder.
Your folder structure should look like:
springboot-demo/
βββ src/
β βββ main/
β β βββ java/com/example/springbootdemo/
β β β βββ SpringbootDemoApplication.java
β β βββ resources/
β β βββ application.properties
β β βββ static/
βββ pom.xml
π Step 3: Run Your Spring Boot Application
Inside SpringbootDemoApplication.java
, youβll find:
@SpringBootApplication
public class SpringbootDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootDemoApplication.class, args);
}
}
βΆοΈ Run From IDE
Click the green run button next to the main()
method or right-click β Run.
π οΈ Run From Terminal
./mvnw spring-boot:run
You should see:
Tomcat started on port(s): 8080 (http)
Started SpringbootDemoApplication in 2.5 seconds
Open a browser and visit http://localhost:8080
π οΈ Step 4: Build a Simple REST API
Letβs create a HelloController.java
to test if our backend is working.
π Create Controller Class
src/main/java/com/example/springbootdemo/controller/HelloController.java
package com.example.springbootdemo.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String sayHello() {
return "Hello, Spring Boot!";
}
}
π Test the API
Now go to your browser and hit: π http://localhost:8080/hello
β
You should see: Hello, Spring Boot!
π§ Bonus: Customize application.properties
Edit src/main/resources/application.properties
:
server.port=9090
spring.application.name=springboot-demo
Re-run your app and visit: π http://localhost:9090/hello
π€ FAQs
Q: Can I add more dependencies later?
π Yes! Add them to pom.xml
and reload your project.
Q: Do I need Tomcat installed? π No, Spring Boot embeds Tomcat by default.
Q: Can I use MySQL/PostgreSQL instead of H2?
π Absolutely. Just add the dependency and update application.properties
.
πͺ Checklist for Hands-On Practice
Task | Status |
---|---|
Create project with Spring Initializr | β |
Open in IDE | β |
Run basic app | β |
Add REST Controller | β |
Customize configuration | β |
Hit API in browser | β |
π Conclusion
Spring Boot makes backend development in Java fast, modular, and fun. With just a few steps, you can spin up a working application and start building real features.
Whether you're building REST APIs, connecting databases, or creating full-stack appsβSpring Boot is the go-to choice for Java developers.
So what are you waiting for? Fire up Spring Initializr and start building!
Posted on May 18, 2025