Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 101

    Spring Boot Exercises

    Hands-on builds cement Boot 3 / Java 21 skills better than another tutorial video.

    Course progress0%
    Focus
    12 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Hands-on builds cement Boot 3 / Java 21 skills better than another tutorial video. Each exercise below is a concrete TechLearningPRO-style service with acceptance criteria, required endpoints, and a definition of done — not vague 'build a CRUD app' fluff.

    Pick one difficulty band, implement end-to-end with Postgres, tests, and a README, then deploy to a free tier. Use jakarta.* only — no javax.*.

    This lesson is your practice backlog for the rest of the course.

    Purpose of this lesson

    Complete graded Spring Boot 3 exercises with explicit acceptance criteria spanning CRUD, auth, messaging, and multi-tenancy.

    Understanding the topic

    Pick your battle — each row is a shippable mini-product.

    • 🟢 URL shortener — POST long URL → slug; GET redirects; 404 for unknown; rate-limit create.
    • 🟢 Notes API — CRUD notes with JWT auth and per-user isolation (no cross-user reads).
    • 🟡 Polls service — create poll, vote once per user, live results via WebSocket.
    • 🟡 Inventory tracker — products, stock movements, low-stock email via async event.
    • 🔴 Payment-like ledger — accounts, transfers, transactional double-entry, idempotent transfer id.
    • 🔴 Multi-tenant SaaS — orgs, users, roles, per-tenant rate limits on Orders-like APIs.

    Step-by-step explanation

    1. Choose one exercise and write acceptance tests before controllers.
    2. Scaffold Boot 3 + Java 21 + Postgres Testcontainers.
    3. Implement vertical slice: API → service → JPA → migrations.
    4. Add Actuator health, Dockerfile, and a README with curl demos.

    Informative example

    Acceptance pack — Notes API (green band).

    bash
    Given a registered user A with a valid JWT
    When A POST /api/notes {"title":"lab","body":"..."}
    Then 201 with note id owned by A
    Given user B's JWT
    When B GET /api/notes/{id-of-A}
    Then 404 (not 403) — no existence leak
    Given A's JWT
    When A DELETE /api/notes/{id}
    Then 204 and subsequent GET returns 404
    Required:
    - Spring Security 6 filter chain, BCrypt passwords
    - Flyway V1__notes.sql
    - @SpringBootTest + Testcontainers Postgres
    - No javax.*; no real SMTP/API keys in repo

    Real-world use

    Candidates who show one deployed Notes or ledger API with Testcontainers and a Grafana screenshot outperform portfolios of ten unfinished Spring Initializr zips. TechLearningPRO hiring loops explicitly ask for isolation tests — the green Notes exercise trains that muscle.

    Security implications

    Every exercise must treat authz as a first-class acceptance test.

    • Assert cross-user access fails.
    • Store password hashes only; never log raw passwords.
    • Use env placeholders for any third-party tokens.

    Best practices

    • One exercise fully done beats three half-done.
    • Commit migrations and OpenAPI with the code.
    • Document how to run tests with zero manual setup.

    Common mistakes

    • Building UI before the API contract and tests exist.
    • Hardcoding secrets or using javax.persistence from old blogs.
    • Skipping idempotency on the ledger transfer endpoint.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    3 questions
    1IntermediateQuestionWhy return 404 instead of 403 for another user's note?+

    Answer

    Avoid confirming that the resource exists to a different principal — common IDOR hardening.
    2AdvancedQuestionWhat makes the ledger exercise 'senior'?+

    Answer

    Idempotent money movement, transactional double-entry, and auditability under retries.
    3BeginnerQuestionWhy Testcontainers in these exercises?+

    Answer

    They prove the schema and SQL work against real Postgres, not only mocks.

    Hands-on exercise

    Challenge set (pick 2). 1) Ship the Notes API with the acceptance pack above. 2) Extend URL shortener with custom aliases + collision handling. 3) Ledger: implement transfer with unique transferId so retries do not double-post. Submit: GitHub link, test output, and a 5-bullet postmortem of what broke first.

    Summary

    These exercises are your portfolio engine. Next: sharpen API design with REST challenges.

    Ready to mark this lesson complete?Track your journey across the entire course.