Free course · 35 lessons · Intermediate
Spring Boot: From Basics to Production
Build and run Java 21 services with Spring Boot: dependency injection, REST APIs, validation, Spring Data JPA, Spring Security with JWT, testing with Testcontainers, observability and deployment.
1. Spring Core and Spring Boot Fundamentals
Create a Spring Boot app and understand dependency injection, beans, configuration and auto-configuration.
- Creating a Spring Boot Project — Generate a project with Spring Initializr, run it and understand its structure.
- Dependency Injection and Beans — Let Spring create and wire your components through constructors.
- Configuration Properties and Profiles — Externalize configuration with application.yml, typed properties and profiles.
- Auto-configuration and Starters — Understand how Boot configures beans for you and how to override it.
- Bean Scopes, Lifecycle and Events — Singletons, prototype scope, initialization hooks and application events.
2. Building REST APIs with Spring MVC
Controllers, request data, DTOs, HTTP clients and API documentation.
- REST Controllers and Response Handling — Map HTTP endpoints, return proper status codes and headers.
- Path Variables, Query Parameters, Headers and Bodies — Read every kind of request input safely.
- DTOs with Records and JSON Mapping — Model requests and responses with Java records and control JSON output.
- Calling Other APIs with RestClient — Make HTTP calls with RestClient, timeouts and error handling.
- API Documentation with springdoc-openapi — Generate OpenAPI docs and Swagger UI from your controllers.
3. Validation and Error Handling
Bean Validation, custom constraints and consistent Problem Details errors.
- Bean Validation — Validate requests with Jakarta Bean Validation annotations.
- Global Error Handling with Problem Details — Return RFC 9457 Problem Details consistently with @RestControllerAdvice.
- Custom Constraints and Cross-Field Validation — Write reusable validation annotations and class-level checks.
4. Persistence with Spring Data JPA
Entities, repositories, queries, transactions, relationships and Flyway migrations.
- Entities and Repositories — Map tables to entities and get CRUD for free with JpaRepository.
- Queries: Derived, JPQL, Native and Projections — Express queries with method names, @Query and DTO projections.
- Transactions with @Transactional — Define transaction boundaries and avoid the common proxy pitfalls.
- Relationships and the N+1 Problem — Map associations sensibly and fetch them efficiently.
- Schema Migrations with Flyway — Version the database schema and run migrations on startup or in CI/CD.
5. Securing APIs with Spring Security
Security filter chains, authentication, JWT resource servers, method security, CORS and CSRF.
- How Spring Security Works — Configure the SecurityFilterChain with the lambda DSL.
- Users, Passwords and Authentication Providers — Load users from the database and hash passwords properly.
- JWT Resource Server with OAuth2/OIDC — Validate access tokens from an identity provider.
- Method Security and Object-Level Authorization — Protect service methods with @PreAuthorize and ownership checks.
- CORS, CSRF and Security Headers — Configure browser-related protections correctly.
6. Testing Spring Boot Applications
Unit tests, web slice tests, JPA tests with Testcontainers and full integration tests.
- Unit Tests with JUnit 5 and Mockito — Test services fast, without starting Spring.
- Web Layer Tests with @WebMvcTest and MockMvc — Test controllers, validation, JSON and security without the full app.
- Repository Tests with Testcontainers — Test queries against a real PostgreSQL in Docker.
- Full Integration Tests with @SpringBootTest — Test the whole application through HTTP with real infrastructure.
7. Observability with Actuator and Micrometer
Health checks, metrics, tracing and structured logging for production.
- Spring Boot Actuator — Expose health, info and operational endpoints safely.
- Metrics with Micrometer and Prometheus — Measure what matters with timers, counters and observations.
- Distributed Tracing with Micrometer Tracing and OpenTelemetry — Follow requests across services and correlate logs.
- Structured Logging — Emit JSON logs with context for log aggregation.
8. Deployment and Performance
Containers, virtual threads, native images and caching.
- Packaging and Container Images — Build efficient images with layered JARs or Cloud Native Buildpacks.
- Virtual Threads — Handle more concurrent blocking requests with Java 21 virtual threads.
- GraalVM Native Images — Compile Spring Boot apps ahead-of-time for fast startup and low memory.
- Caching with Spring's Cache Abstraction — Cache expensive reads with @Cacheable and Redis or Caffeine.