About This Book
This book is a practical guide to building applications with Spring and its alternatives. It covers the core framework, data access, messaging, batch processing, cloud-native deployment, and the frameworks that compete with Spring — each explained through working code.
What You Will Find
Every chapter pairs explanation with code. Concepts are introduced through self-contained examples that build toward production-ready patterns. Where a topic has depth — like transaction propagation or Kafka consumer groups — the chapter walks through the mechanics before showing the pattern.
The book is organized in seven parts:
Core starts with the IoC container, bean lifecycle, and component scanning, then covers dependency injection patterns and aspect-oriented programming with Spring AOP.
Web & REST covers Spring Boot REST APIs, Spring MVC web applications, exception handling, content negotiation, and Jackson serialization patterns.
Data & Persistence digs into Spring Data with Hibernate, JdbcTemplate, connection pooling, and transaction management — including propagation, isolation levels, and the Saga pattern.
Messaging & Events covers RabbitMQ and Kafka with Spring, application events, domain events, dead letter queues, and event-driven architecture.
Batch & Workflow addresses Spring Batch for chunk-oriented processing and state machines for modeling complex business workflows.
Cloud & Deployment covers Docker and Kubernetes with Spring Boot, health checks, Helm charts, and serverless computing with Spring Cloud Function on AWS Lambda, Azure, and Google Cloud.
Alternative Frameworks presents Quarkus with GraalVM native images, Jakarta EE, and plain Java REST without frameworks — so you can choose the right tool for each situation.
Who This Book Is For
This book is for Java developers who build server-side applications. Whether you are adopting Spring for the first time, migrating between frameworks, or looking to understand what happens behind the annotations, you will find material here that applies directly to your work.
Familiarity with Java is assumed. The companion volume covers the language, standard libraries, and JVM internals.
How to Read This Book
The parts are self-contained. You can read front to back or jump to the topic you need. Within each chapter, code examples build on each other, so reading a chapter in order works best.
Code listings use Spring Boot 3 and Java 21 unless noted otherwise.
Part I: Core
Chapter 1: Spring Core IoC
- ApplicationContext and BeanFactory
- Bean lifecycle and scopes (singleton, prototype, request, session)
- Component scanning and stereotype annotations
- Java-based and annotation configuration
- Profiles and conditional beans
- Property sources and Environment abstraction
Chapter 2: Dependency Injection
- Constructor, setter, and field injection
- @Qualifier, @Primary, and custom qualifiers
- Circular dependency resolution
- Provider and ObjectFactory for lazy resolution
- Custom scopes
- DI without Spring: CDI, Guice, Dagger
Chapter 3: Spring AOP
- Aspect, advice, and pointcut model
- Before, after, around, and after-throwing advice
- Annotation-driven aspects
- Proxy mechanics (JDK dynamic proxy vs. CGLIB)
- Custom annotations with AOP
- Performance monitoring and transaction aspects
Part II: Web & REST
Chapter 4: Spring Boot REST
- @RestController and request mapping
- Request/response body handling with Jackson
- Bean Validation (@Valid, custom constraints)
- Exception handling (@ExceptionHandler, @ControllerAdvice)
- Content negotiation (JSON, XML)
- HATEOAS and hypermedia-driven APIs
Chapter 5: Web Applications
- Spring MVC architecture and DispatcherServlet
- Servlet filters, interceptors, and listeners
- Session and cookie management
- WebSocket and Server-Sent Events
- Spring Security integration
- Error pages and global exception handlers
Chapter 6: Serialization Patterns
- Jackson ObjectMapper configuration
- Custom serializers and deserializers
- JSON views, mixins, and polymorphic types
- Date/time serialization strategies
- CSV serialization with Jackson
- Performance tuning and best practices
Part III: Data & Persistence
Chapter 7: Spring Data Hibernate
- Repository pattern and derived query methods
- JPA entity mapping and relationships
- Entity lifecycle and persistence context
- Fetch strategies (LAZY vs. EAGER) and N+1 solutions
- Caching strategies (first-level, second-level, query cache)
- Exception handling and optimistic locking
Chapter 8: Data JDBC
- JdbcTemplate and NamedParameterJdbcTemplate
- RowMapper and ResultSetExtractor patterns
- Batch operations and bulk inserts
- Connection pooling with HikariCP
- Spring Data JDBC aggregates
- Stored procedures and database functions
Chapter 9: Transaction Management
- ACID properties and isolation levels
- @Transactional and propagation levels
- Programmatic vs. declarative transactions
- Rollback rules and exception handling
- Distributed transactions and the Saga pattern
- Testing transactional code
Part IV: Messaging & Events
Chapter 10: Messaging with RabbitMQ and Kafka
- Messaging fundamentals and broker architecture
- RabbitMQ exchanges, queues, and Spring AMQP
- Kafka producers, consumers, and stream processing
- Spring Cloud Stream for broker-agnostic code
- Dead letter queues, retry, and idempotency
- WebSocket integration for real-time updates
Chapter 11: Application Events
- ApplicationEvent and @EventListener
- Synchronous and asynchronous event handling
- Domain events and event publishing
- Event sourcing and CQRS fundamentals
- Spring Integration channels and gateways
- Event-driven microservices patterns
Part V: Batch & Workflow
Chapter 12: Spring Batch
- Job, step, and chunk-oriented processing
- ItemReader, ItemProcessor, ItemWriter
- Tasklet steps for simple operations
- Parallel and partitioned step execution
- Retry, skip, and restart policies
- Job scheduling, monitoring, and observability
Chapter 13: State Machines
- Enum-based state machines with transition logic
- Record-based state transitions and pattern matching
- Sealed interfaces for type-safe state hierarchies
- Spring State Machine framework
- Guards, actions, and hierarchical states
- Persistent and distributed state machines
Part VI: Cloud & Deployment
Chapter 14: Docker and Kubernetes
- Dockerfile and multi-stage builds for Spring Boot
- Layered JARs and Buildpacks
- Kubernetes Deployments, Services, and ConfigMaps
- Health checks (liveness, readiness, startup probes)
- Rolling updates, blue-green, and canary deployments
- Service discovery, observability, and Helm charts
Chapter 15: Serverless with Spring Cloud Function
- Function, Supplier, and Consumer beans
- Platform-agnostic deployment across cloud providers
- AWS Lambda with Spring Cloud Function adapter
- Cold start optimization and GraalVM native images
- Local testing with JUnit and LocalStack
- Production patterns and cost optimization
Part VII: Alternative Frameworks
Chapter 16: Quarkus and GraalVM
- Build-time optimization and dev mode
- GraalVM native image compilation (AOT vs. JIT)
- REST APIs with RESTEasy Reactive
- Database access with Panache (active record and repository)
- Reactive programming with Mutiny
- Configuration profiles and testing strategies
Chapter 17: Jakarta EE
- CDI, JAX-RS, JPA, and Bean Validation
- Entity graphs and conditional HTTP requests (ETag)
- Interceptors and providers for cross-cutting concerns
- Transaction boundaries and concurrency control
- Correlation filters and observability
- Testing with Arquillian and embedded containers
Chapter 18: Plain Java REST
- HTTP server with embedded Jetty (no frameworks)
- Custom routing and handler patterns
- Direct JDBC with HikariCP connection pooling
- JSON processing with Jackson ObjectMapper
- Manual dependency wiring and service locator
- Error handling, structured logging, and testing