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.

Start the course

1. Spring Core and Spring Boot Fundamentals

Create a Spring Boot app and understand dependency injection, beans, configuration and auto-configuration.

  1. Creating a Spring Boot Project — Generate a project with Spring Initializr, run it and understand its structure.
  2. Dependency Injection and Beans — Let Spring create and wire your components through constructors.
  3. Configuration Properties and Profiles — Externalize configuration with application.yml, typed properties and profiles.
  4. Auto-configuration and Starters — Understand how Boot configures beans for you and how to override it.
  5. 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.

  1. REST Controllers and Response Handling — Map HTTP endpoints, return proper status codes and headers.
  2. Path Variables, Query Parameters, Headers and Bodies — Read every kind of request input safely.
  3. DTOs with Records and JSON Mapping — Model requests and responses with Java records and control JSON output.
  4. Calling Other APIs with RestClient — Make HTTP calls with RestClient, timeouts and error handling.
  5. 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.

  1. Bean Validation — Validate requests with Jakarta Bean Validation annotations.
  2. Global Error Handling with Problem Details — Return RFC 9457 Problem Details consistently with @RestControllerAdvice.
  3. 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.

  1. Entities and Repositories — Map tables to entities and get CRUD for free with JpaRepository.
  2. Queries: Derived, JPQL, Native and Projections — Express queries with method names, @Query and DTO projections.
  3. Transactions with @Transactional — Define transaction boundaries and avoid the common proxy pitfalls.
  4. Relationships and the N+1 Problem — Map associations sensibly and fetch them efficiently.
  5. 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.

  1. How Spring Security Works — Configure the SecurityFilterChain with the lambda DSL.
  2. Users, Passwords and Authentication Providers — Load users from the database and hash passwords properly.
  3. JWT Resource Server with OAuth2/OIDC — Validate access tokens from an identity provider.
  4. Method Security and Object-Level Authorization — Protect service methods with @PreAuthorize and ownership checks.
  5. 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.

  1. Unit Tests with JUnit 5 and Mockito — Test services fast, without starting Spring.
  2. Web Layer Tests with @WebMvcTest and MockMvc — Test controllers, validation, JSON and security without the full app.
  3. Repository Tests with Testcontainers — Test queries against a real PostgreSQL in Docker.
  4. 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.

  1. Spring Boot Actuator — Expose health, info and operational endpoints safely.
  2. Metrics with Micrometer and Prometheus — Measure what matters with timers, counters and observations.
  3. Distributed Tracing with Micrometer Tracing and OpenTelemetry — Follow requests across services and correlate logs.
  4. Structured Logging — Emit JSON logs with context for log aggregation.

8. Deployment and Performance

Containers, virtual threads, native images and caching.

  1. Packaging and Container Images — Build efficient images with layered JARs or Cloud Native Buildpacks.
  2. Virtual Threads — Handle more concurrent blocking requests with Java 21 virtual threads.
  3. GraalVM Native Images — Compile Spring Boot apps ahead-of-time for fast startup and low memory.
  4. Caching with Spring's Cache Abstraction — Cache expensive reads with @Cacheable and Redis or Caffeine.