Initial Setup
Get Spring Boot installed and create your first web application. This guide walks you through installation and building your first Spring Boot app.
π― What You’ll Accomplish
By the end of this tutorial, you’ll have:
- β Java and Spring Boot set up
- β Your first Spring Boot project created
- β REST API endpoint running
π Prerequisites
- Java 17 or later
- Maven or Gradle
- IDE (IntelliJ IDEA, Eclipse, or VS Code)
πΎ Step 1: Create Spring Boot Project
Visit start.spring.io and create a project with:
- Spring Boot 3.2.x
- Dependencies: Spring Web
Or use command line:
curl https://start.spring.io/starter.zip \
-d dependencies=web \
-d bootVersion=3.2.0 \
-d javaVersion=17 \
-o spring-boot-demo.zip
unzip spring-boot-demo.zip
cd spring-boot-demoπ Step 2: Create Your First Controller
Create src/main/java/com/example/demo/HelloController.java:
package com.example.demo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/")
public String hello() {
return "Hello, Spring Boot!";
}
@GetMapping("/api/greeting")
public Greeting greeting() {
return new Greeting("Hello, World!");
}
}
record Greeting(String message) {}π Step 3: Run the Application
./mvnw spring-boot:run
# Or with Gradle
./gradlew bootRunVisit:
http://localhost:8080/- See hello messagehttp://localhost:8080/api/greeting- See JSON response
β Verification Checklist
Before moving forward, verify:
- Project created successfully
- Application starts without errors
- Endpoints respond correctly
π You’re Done!
You’ve successfully created your first Spring Boot web application.
π What’s Next?
Quick learner: Java Spring Boot Quick Start
Code-first learner: Java Spring Boot By Example
Last updated