0PricingLogin
Spring Boot 4 Microservices & REST APIs · Lesson

Bean Validation with @Valid

Validate request bodies with annotations.

Bean Validation Overview

Bean Validation (JSR-380, Jakarta Validation) lets you declare constraints with annotations on your DTO fields, then validate objects against them. Spring Boot integrates it so incoming request bodies are checked automatically.

Adding the Dependency

The validation API plus an implementation (Hibernate Validator) come via the validation starter. Adding it activates annotation-driven validation in controllers.

<!-- pom.xml -->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-validation</artifactId>
</dependency>

All lessons in this course

  1. Bean Validation with @Valid
  2. Custom Validators
  3. @ControllerAdvice and @ExceptionHandler
  4. Problem Details (RFC 7807)
← Back to Spring Boot 4 Microservices & REST APIs