π Spring Boot Quickstart π₯π₯π₯
Your first steps into the Spring ecosystem, creating the foundation of our Todo application. β±οΈ Time: 30 mins
π What Youβll Build
- A Todo project scaffolded with Spring Initializr
- Your first Spring Boot app that says:
Hello, Todo!
- A working understanding of Spring Bootβs auto-configuration
- A REST endpoint, served locally in your browser
π Key Concepts
- Spring Boot project structure
@SpringBootApplication
β the main entry point@RestController
β define simple APIsapplication.properties
β basic configuration
π§° Prerequisites
Install the following:
β Java 17+
-
macOS:
brew install openjdk@17 export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH"
-
Ubuntu / Debian:
curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" sdk install java 17
-
Windows (PowerShell):
winget install -e --id Microsoft.OpenJDK.17
Restart your terminal so the new JDK is on your PATH.
β Maven
-
macOS:
brew install maven
-
Ubuntu / Debian:
sudo apt update sudo apt install maven
-
Windows (PowerShell):
winget install -e --id Apache.Maven
β VS Code
- Download: https://code.visualstudio.com
-
Extensions:
- Java Extension Pack β
- Spring Boot Extension Pack (optional)
π οΈ Hands-on: Build the Todo App
1οΈβ£ Create a Project (Spring Initializr)
macOS / Ubuntu / Windows: Both workflows below are identical across operating systems because Spring Initializr and VS Code provide the same UI everywhere.
π¦ Option A: Inside VS Code
-
Open Command Palette:
- macOS:
β§βP
- Windows/WSL:
Ctrl+Shift+P
- macOS:
-
Run:
Spring Initializr: Generate a Maven Project
-
Fill in:
- Language: Java
- Spring Boot Version: 3.2.x
- Group:
com.example
- Artifact/Name:
demo
- Package:
com.example.demo
- Dependency:
Spring Web
-
Choose folder β Open in VS Code
π¦ Option B: start.spring.io
- Same values as above
- Download and unzip β Open in VS Code
2οΈβ£ Understand the Structure
macOS / Ubuntu / Windows: The generated project layout is identical on every platform.
demo/
βββ src/main/java/com/example/demo/DemoApplication.java
βββ src/main/resources/application.properties
βββ pom.xml
DemoApplication.java
β Main classapplication.properties
β Configpom.xml
β Maven dependencies
3οΈβ£ Add Your First Endpoint
macOS / Ubuntu / Windows: Create the controller class in the same package path; file navigation in VS Code or your editor is consistent across OSes.
Create TodoController.java
:
package com.example.demo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TodoController {
@GetMapping("/hello")
public String hello() {
return "Hello, Todo!";
}
}
4οΈβ£ Run the App
π§βπ» VS Code Run Button
Open DemoApplication.java
and press βΆοΈ. Output should say Tomcat started on port 8080
.
π macOS / Linux Terminal
./mvnw spring-boot:run
πͺ Windows (PowerShell or CMD)
PowerShell:
./mvnw.cmd spring-boot:run
Command Prompt:
mvnw.cmd spring-boot:run
π³ Run via Docker (sample project)
To run the already-created sample project (spring-zero-to-hero-codes
) inside a container, make sure Docker Desktop is running, clone the repo, then from that project folder execute:
docker compose up --build
Code edits on your machine are reflected immediately in the container thanks to the bind mount. By default the container exposes http://localhost:8080/hello
; if you change server.port
, update the URL accordingly. Stop the container with docker compose down
when finished.
5οΈβ£ Test in Your Browser
macOS / Ubuntu / Windows: Open a browser on your machine (Edge, Chrome, Safari, Firefoxβyour choice) and hit the URL; the response is the same on every OS.
Visit:
http://localhost:8080/hello
β
Youβll see: Hello, Todo!
6οΈβ£ Configure Your App
macOS / Ubuntu / Windows: Edit application.properties
using your editor; property locations are identical across platforms.
Edit src/main/resources/application.properties
:
server.port=8080
spring.application.name=todo-app
Restart the app. Now visit:
http://localhost:8080/hello
Want to try a different port? Change server.port
to 9090
, restart, and hit http://localhost:9090/hello
.
β Outcome
By now, youβve:
- Created a Spring Boot project
- Built and tested your first REST API
- Modified application settings