Validation, Global Exception Handling, Logging and API Versioning
Learn Validation, Global Exception Handling, Logging and API Versioning (Phase 2 · Spring Boot Microservices (Essential), Microservices) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Validation • Use Jakarta Bean Validation ( spring-boot-starter-validation ): annotate DTOs ( @NotBlank , @Size , @Email , @Min , @Positive , @Pattern , @Valid for nesting), trigger with @Valid @RequestBody , validate path/query params with @Validated on the class and constraints on parameters. Custom constraints ( @ValidSlug ) for domain rules; cross-field via class-level constraints. • Validate at the edge (controller) for format, and in the domain for business invariants. Fail with 400/422 and field-level messages. Never trust data from other services either (defensive consumers).