🏁 Spring Boot Quickstart πŸ”₯πŸ”₯πŸ”₯

Your first steps into the Spring ecosystem, creating the foundation of our Todo application. ⏱️ Time: 30 mins


πŸš€ What You’ll Build


πŸ“˜ Key Concepts


🧰 Prerequisites

Install the following:

βœ… Java 17+


βœ… Maven


βœ… VS Code


πŸ› οΈ 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

  1. Open Command Palette:

    • macOS: β‡§βŒ˜P
    • Windows/WSL: Ctrl+Shift+P
  2. Run: Spring Initializr: Generate a Maven Project

  3. Fill in:

    • Language: Java
    • Spring Boot Version: 3.2.x
    • Group: com.example
    • Artifact/Name: demo
    • Package: com.example.demo
    • Dependency: Spring Web
  4. Choose folder β†’ Open in VS Code

πŸ“¦ Option B: start.spring.io


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

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: