Spring Boot Exercises
Hands-on builds cement Boot 3 / Java 21 skills better than another tutorial video.
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
- Choose one exercise and write acceptance tests before controllers.
- Scaffold Boot 3 + Java 21 + Postgres Testcontainers.
- Implement vertical slice: API → service → JPA → migrations.
- Add Actuator health, Dockerfile, and a README with curl demos.
Informative example
Acceptance pack — Notes API (green band).
Given a registered user A with a valid JWTWhen A POST /api/notes {"title":"lab","body":"..."}Then 201 with note id owned by AGiven user B's JWTWhen B GET /api/notes/{id-of-A}Then 404 (not 403) — no existence leakGiven A's JWTWhen A DELETE /api/notes/{id}Then 204 and subsequent GET returns 404Required:- 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.persistencefrom old blogs. - Skipping idempotency on the ledger transfer endpoint.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1IntermediateQuestionWhy return 404 instead of 403 for another user's note?+
Answer
2AdvancedQuestionWhat makes the ledger exercise 'senior'?+
Answer
3BeginnerQuestionWhy Testcontainers in these exercises?+
Answer
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.